Solved

C++ if commend select probbelm

Posted on 2016-08-30
2
49 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 34

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

729 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