help

Page 1 of 1

2 Replies - 178 Views - Last Post: 19 April 2013 - 11:18 PM Rate Topic: -----

#1 makeitloud  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 64
  • Joined: 08-April 13

help

Posted 19 April 2013 - 10:03 PM

#include <iostream>
#include <string>
#include <ctime>
using namespace std;

int main()
{
	srand (time(NULL));

	int grade, operands[2], userAnswer;

	string quiz, name;

	char answer, again;

	cout << "What is your name?\n";
	cin >> name;
	cout << "Were going to take a quiz, are you ready? <y/n>\n";
	cin >> answer;
	if(answer == 'y' || answer == 'Y')
	{
	cout << "Ok lets get started " << name << endl;
		cout << "First lets do a math problem.\n";
		operands[0] = rand()%50;
		operands[1] = rand()%20;

		cout << "What is " << operands[0] << " + " << operands[1] << " ?\n";
		cin >> userAnswer;
	if(userAnswer==operands[0] + operands[1])
	{
		cout << "You got the Problem right, off to the next question\n";
	}
	else
		{
		cout << "Problem incorrect\n";
		cout << "Would you like to try again?\n";
		cin >> again;
		}
		
		
		
	}
	
	
	

	system("pause");
	return 0;
}



i wanna make it so when you get the answer wrong itll ask the question again. how would i go about to do that, a person told me to use a do while loop but i dont no how i would put that in.

Is This A Good Question/Topic? 0
  • +

Replies To: help

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4421
  • View blog
  • Posts: 12,286
  • Joined: 18-April 07

Re: help

Posted 19 April 2013 - 11:16 PM

Follow the pseudocode...

Ask user for input
Collect answer

while test for answer bad
    ask for input
    collect answer
end while

process answer as normal



:)
Was This Post Helpful? 0
  • +
  • -

#3 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10803
  • View blog
  • Posts: 40,273
  • Joined: 27-December 08

Re: help

Posted 19 April 2013 - 11:18 PM

You've already asked this on your existing thread. Also, please use a descriptive title for your threads.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1