Jump to content

please help with the catching up choices.....

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1
joie2

joie2

    Newbie

  • Members
  • PipPip
  • 17 posts
below is code that would display the game title,authors of it,then a menu..first if there's nothing that have been save the only menu that would appear are new game,top score and quit...but if you'll change or there's a save game it has a continue menu...
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


#2
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
Place your code between CODE tags. ie)

[noparse]
#include <iostream>
...
[/noparse]

#3
dcs

dcs

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 775 posts

joie2 said:

below is code that would display the game title,authors of it,then a menu..first if there's nothing that have been save the only menu that would appear are new game,top score and quit...but if you'll change or there's a save game it has a continue menu...
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...
Using a question mark in there somewhere might have indicated to me some form of question. I'm sure there is at least one there, but I don't know what you might be trying to ask.

#4
Phoenixz

Phoenixz

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 256 posts
I believe that his question is;

"How can I make sure that the userinput is a word, or numbers, and that it is valid."

You can use strcpy, strcat, or if it's like 1 character; if (variable == 'Character') (or if it's multiple, cases would do)

I'm sure there will be other ways, perhaps better too.
Posted Image

#5
Feral

Feral

    Programmer

  • Members
  • PipPipPipPip
  • 162 posts
You are already including ctype.h for toupper, the same header gives you access to isalnum and isalpha which check to see if the input is alphanumeric and alphabetic.

see here for a full list of the function in the ctype.h header

#6
joie2

joie2

    Newbie

  • Members
  • PipPip
  • 17 posts
how could i catch the userinput if it will enter a string or a word..word with a number or numbers....

#7
dcs

dcs

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 775 posts
If you are trying to verify that user input for a numeric value is indeed a number, check out the snippets linked here:

http://forum.codecal...-numbers-c.html

And read the tutorial for its full value as well.