the other thing is that i let the userinout and the check be on a upper case so that it would convert the userinput even he/she input a lower case choice..
the only thing a headache is that how could a catch that if the userinput is a word or a numbers it is invalid...
please help me...
#include<iostream>
#include<string>
#include<ctype.h>
using namespace std;
class tech
{
public:
string title;
string gname;
string que;
string choicesA,choicesB,choicesC;
char check,userinput;
string menu;
int cnt;
void displaytitle(string title);
void displaygname(string gname);
void displayque(string que);
void displaychoices(string choicesA,string choicesB,string choicesC);
void displaycheck(char check);
void displaymenu();
};
void tech::displaytitle(string title){
cout<<title<<endl;
}
void tech::displaygname(string gname){
cout<<gname<<endl;
}
void tech::displaymenu(){
cout<<"Select Menu:\n(1)New Game\n(2)Top Score\n(3)Quit\n";
}
void tech::displayque(string que){
cout<<que<<endl;
}
void tech::displaychoices(string choicesA,string choicesB,string choicesC){
cout<<choicesA<<choicesB<<choicesC<<endl;
}
void tech::displaycheck(char check){
cin>>userinput;
if(topupper(userinput)==topupper(check))
{
cnt=0;
cnt = cnt + 1;
cout<<cnt;
cout<<"correct";
}
else{
cout<<"invalid";
}
}
main ()
{
int c;
tech first;
first.displaytitle("WELCOME Game Name");
first.displaygname("authors");
first.displaymenu();
cin>>c;
switch(c)
{
case 1:
first.displayque("First question...");
first.displaychoices("a.choice","b.choices","c.choosen");
first.displaycheck('a');
break;
case 2:
cout<<"top score";
break;
case 3:
cout<<"quit";
break;
}
return 0;
}
Edited by John, 09 February 2010 - 07:12 PM.
Use [code] tags


Sign In
Create Account


Back to top










