Teen Programmers Unite  
 

 

Return to forum top

C++:Math Program

Posted by MARK [send private reply] at February 03, 2002, 06:30:37 PM

Hello all,

I am writing a program that will add, sub, mult,divsion. The numbers will be random,and I am using functions for this. I want to give the user 3 problems per type of problem, and I am using a for loop to ask the next problem. After three problems of the add type are done I want to show the amount right/wrong. This is where I am stuck. I would like to show the correct and wrong answerd the user gave and display that amount in int main or my int menu. I am not seeing how I should do this.

THanks.
Mark.

Posted by CodeRed [send private reply] at February 03, 2002, 07:41:54 PM

Something like this maybe:

int num1 = rand()%WhateverYouWant
int num2 = rant()%WhateverYouWant
int answer = num1 + num2;
int response;

cout << num1 << " + " << num2 << " = " << endl;
cin >> response;

if(response == answer)cout << "Congratulations";
else cout << "Wrong, the correct answer is " << answer;

Posted by MARK [send private reply] at February 03, 2002, 08:48:22 PM

Thanks CodeRed,

I am going to try something like you suggested and then use a for loop to count the total wrong/right.

Posted by Psion [send private reply] at February 04, 2002, 07:56:48 AM

This question was not appropriate to post here. Ask your teacher if you don't understand such basic things.

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.