Can someone explain these two functions to me? I don't
understand how to use them correctly.
Here is a very simple program, and all I want it to do is return
a the value for what they enter:
I know I used getch wrong, because I don't know how to use it.
Can someone help?
understand how to use them correctly.
Here is a very simple program, and all I want it to do is return
a the value for what they enter:
Code:
#include <iostream.h>
#include <process.h>
#include <conio.h>
int menu();
void main()
{
int ans;
ans = menu();
// menu function after main section
if (ans == 1)
cout << "1";
else if (ans == 2)
cout << "2";
else if (ans == 3)
cout << "3";
else if (ans == 4)
cout << "4";
}
int menu()
{
cout << "+----------------------------+ \n";
cout << "| DODGER | \n";
cout << "+----------------------------+ \n";
cout << "| WHERE WOULD YOU LIKE TO | \n";
cout << "| GO TODAY? | \n";
cout << "+----------------------------+ \n";
cout << "|1: Play the game | \n";
cout << "+----------------------------+ \n";
cout << "|2: Instructions | \n";
cout << "+----------------------------+ \n";
cout << "|3: Quit | \n";
cout << "+----------------------------+ \n";
cout << "| Press the number that | \n";
cout << "| corresponds to your choice | \n";
cout << "+----------------------------+ \n";
if(getch()==1)
{
return 1;
}
else if (getch() == 2)
{
return 2;
}
else if (getch()==3)
{
return 3;
}
else return 4;
}
Can someone help?