Smoother exit ideas?

need a better way letting the user exit

Page 1 of 1

1 Replies - 566 Views - Last Post: 09 November 2009 - 09:47 PM Rate Topic: -----

#1 Engromada  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 05-November 09

Smoother exit ideas?

Post icon  Posted 09 November 2009 - 07:55 PM

The idea is to ask basic addition questions untill the user wants to quit.

In reality, it asks you if you want to quit yet after every question.

I'd rather the user was able to just answer questions uninterupted untill they wanted to quit...

I have looked into detecting keystrokes to add something like being able to push 'X' at any time to exit, but that seems to be advanced stuff.

I was thinking of changing the answer input to be something like:
"enter your answer or x to quit", perhaps?

I also thought of having sets 10 questions then asking if the user wants to quit or do 10 more..

Any thoughts, please?

Sorry if my code is a bit of a muddle.
#include <iostream>
#include <time.h>

using namespace std;

int a, b, c, x, y, n, q=1;	
/*
a, b and c = first number, second number, answer.
x is the users answer guess.
y and n are score counters, y for correct answers, n for incorrect.
q is quit or get another question toggley thingamyjig.
*/

int askquestion();
int quitorcon();
int gratsfail();

int gratsfail() // lets you know if you were right and adds to score counters.
{
	if(x == c)
	{
		cout << "Grats!\n";
		y++;		
	}
	else
	{
		cout << "FAIL!\n";
		n++;
	}
	quitorcon();
	return 0;
}



int quitorcon() // asks uer to enter 1 to keep playing, or another number to quit.
{
	cout << "\nType 1 for another, or any other *number* to quit.\n";
	cin >> q;
	if(q == 1)
	{
		askquestion();
	}
	else
	{	
		cout << "You got " << y << " correct and " << n <<  " incorrect.\n\nThanks for playing!\n";

		system("pause");
		exit(1);
	}
}

int askquestion() // asks a math question then goes to the gratsfail function.
{
	srand ( time(NULL) );		// initialize random seed
	a = rand() % 100 +1;		// set a&b to random numbers between 1 and 100.
	b = rand() % 100 +1;
	c = a + b;					// set answer.

	cout << "What is " << a << " + " << b << "?\n";		// whats a+b?
	cin >> x;	//get answer guess

	gratsfail();
	return 0;
}


int main()
{
	cout << "Welcome to Engromada's immensely simple simple addition game.\n\n";

	askquestion();
	
	return 0;
} 


PS. my first ever non-tutorial program, right there ^ :D (yay!)
took me literally all day to work out how to make it, but it sure was fun!

so, no mocking my noobcode, unless the mockery comes by PM and in constructive criticism flavour! =)

This post has been edited by Engromada: 09 November 2009 - 08:20 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Smoother exit ideas?

#2 Engromada  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 05-November 09

Re: Smoother exit ideas?

Posted 09 November 2009 - 09:47 PM

Okay, just in case anyone is interested... i fixed it myself! hehe. =)

I just changed my "shall i quit" variable from an integer to a string array thing, then used string compare instead of an "quit == 1" to determine wether to quit, and gave the option to quit only every 10 questions, also resetting the program every ten q's.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1