Solved

C++ if commend select probbelm

Posted on 2016-08-30
2
40 Views
Last Modified: 2016-08-30
I have a problem in  c++ in Code::Blocks, do i something wrong whit my if statement !

i Get the error label: error : label 'gravetie' used but not defind same whit the other if statements

#include <iostream>

using namespace std;

int main()
{
    int command;
    int pause;
    cout << "#############################################################################" << endl;
    cout << "###                                                                       ###" << endl;
    cout << "###                     P I R O M         S.T.A.                          ###" << endl;
    cout << "###                                                                       ###" << endl;
    cout << "#############################################################################" << endl;
    cout << "###                                                                       ###" << endl;
    cout << "###        1.  Run TEST Gravetie                                          ###" << endl;
    cout << "###        2.  Run TEST beometrics                                        ###" << endl;
    cout << "###        3.  Run TEST DNA                                               ###" << endl;
    cout << "###        4.  Run TEST LCARS                                             ###" << endl;
    cout << "###        5.  Run TEST telportasion                                      ###" << endl;
    cout << "#############################################################################" << endl;
    cout << "###        5.  Run D.R.A.R.P.A                                            ###" << endl;
    cout << "#############################################################################" << endl;
    cout << "###                                                                       ###" << endl;
    cout << "###                                                                       ###" << endl;
    cout << "###        0. Exit                                                        ###" << endl;
    cout << "###                                                                       ###" << endl;
    cout << "#############################################################################" << endl;
    cin >> command;
    if (command == 1) goto gravetie;
    if (command == 2)  goto beometrics;
    if (command == 3)  goto DNA;
    if (command == 4)  goto LCARS;
    if (command == 5)  goto darpa;
    if (command == 0)  goto exit;


switch (command)
{
case  'gravetie' :
    cout << "gravetie" << endl;

case 'beometrics':
    cout << "beometrics" << endl;
case 'DNA':
    cout << "DNA" << endl;
case 'LCARS':
    cout << "LCARS" << endl;
case 'darpa':
    cout << "darpa" << endl;
case 'telportasion':
    cout << "telportasion" << endl;


}
cin >> pause;
    exit:
    return 0;
}
0
Comment
Question by:Nadir Van Thielen
2 Comments
 
LVL 33

Accepted Solution

by:
ste5an earned 500 total points
ID: 41776095
As the error tells you, you don't have defined any label in your code. I guess you're mixing the switch with it.

switch does not define labels. It it just a different kind of flow-control statement.

And much more important: Never ever use goto. It's evil.

Just remove your if statements. And change your switch to

switch (command)
{
  case 1:
     cout << "gravetie" << endl;
  case 2:
     cout << "beometrics" << endl;
}

Open in new window


And last, but not least: Use the CODE button in the toolbar to embed code in your message.
0
 

Author Closing Comment

by:Nadir Van Thielen
ID: 41776280
thanks for the input
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Parsing XML instructions in Java/any other language.... 3 116
Unresolved External Symbols 3 103
DCT of  2D array using fftw in c++ 9 63
I could not set window to top 4 20
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question