Here i'm trying to finish the 05 lessons by writing up the functions for the voids in their code. But it complains on me, this is what I got so far:
Code:
#include <iostream>
using namespace std;
int playgame();
int loadgame();
int playmultiplayer();
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();
}
int playgame() {
cout<<"Yeaha Baby we're playing!\n";
}
int loadgame() {
cout<<"Bummer.. you cheating bastard, loading a game are you?\n";
}
int playmultiplayer() {
cout<<"Let the multiplayer mayhem begin...\n";
}
I changed void prototypes too int
defined the functions below main
It works too compile, and run but the compiler complains and was wondering if i'm doing something bad....
the compile error:
g++ -c -Wall lesson2.cpp -o lesson2.o
lesson2.cpp: In function ‘int playmultiplayer()’:
lesson2.cpp:47: warning: control reaches end of non-void function
lesson2.cpp: In function ‘int loadgame()’:
lesson2.cpp:44: warning: control reaches end of non-void function
lesson2.cpp: In function ‘int playgame()’:
lesson2.cpp:41: warning: control reaches end of non-void function
g++ lesson2.o -o hello
Originally it looked like this:
Code:
#include <iostream>
using namespace std;
void playgame();
void loadgame();
void playmultiplayer();
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();
}