Solved

C++ if commend select probbelm

Posted on 2016-08-30
2
34 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

773 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