Solved

C++ if commend select probbelm

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
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.

733 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