Solved

C++ if commend select probbelm

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

757 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now