Hey everyone. I'm a new programmer and I have a question about switch case or maybe it has more to do with functions in general. I was reading lesson 5 of the tutorial and i was presented with this block of code:
Code:
#include <iostream>
using namespace std;
void playgame()
{ cout << "Play game called"; }
void loadgame()
{ cout << "Load game called"; }
void playmultiplayer()
{ cout << "Play multiplayer game called"; }
int main()
{
int input;
cout<<"1. Play game\n";
cout<<"2. Load game\n";
cout<<"3. Play multiplayer\n";
cout<<"4. Exit\n";
cout<<"Selection: ";
cin>> input;
switch ( input )
{
case 1: // Note the colon, not a semicolon
playgame();
break;
case 2: // Note the colon, not a semicolon
loadgame();
break;
case 3: // Note the colon, not a semicolon playmultiplayer();
break;
case 4: // Note the colon, not a semicolon
cout<<"Thank you for playing!\n";
break; default: // Note the colon, not a semicolon cout<<"Error, bad input, quitting\n";
break;
}
cin.get();
}
The tutorial stated that the code would compile but not run because the functions were not declared but as I went through the code, I could see any reason why it would not run so I tried to run it and it failed. My question is why would the program not run? It seems the functions that are called upon in the case statement were defined in the beginning of the code. The void playgame() function prints out "Play game called:" on the screen and etc. Is there something I'm just not getting?