I am working on a math tutoring program that asks the user for a seed value, gives them two random numbers from 1 to 500, and asks them to key in the correct answer. So far, here is my source code:

``````#include <iostream>
#include <cstdlib>
#include <time>
#include <conio>
using namespace std;
int main()
{
unsigned seed;
int = rand();
cout << "Enter a seed value: " ;
cin  >> seed;
srand(time(0));
cout << rand()%500 <<endl;
cout << rand()%500 <<endl;
sum = rand() + rand();
cout << "What are the sum of the two numbers? " ;
cin  >> sum;
getch();
return 0;
}``````

However, I am so confused right now: I've feel as if I've hit a brick wall.
Here's my problem:

1. I have no idea how to check and see if the number that they input is the correct answer. (I know it has something to do with the if/else loop). Is there a variable that I have to use??
2. I don't know what formula to use to add the two random numbers up. I tried `int num = rand` at the suggestion of someone, but Ive deleted that part because I couldn't figure out where it went. :cry: I've even tried to declare rand() as an int variable, but all I got was an error message.

Please keep in mind that I am new at this C++, and I am here to learn. :eek: I type this program myself, I've read my textbook, and I still got stuck. Please help me. :sad:

conio.h is non standard, remove that and replace the getch() with cin.get()

And it should be <ctime> not <time>

``````#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;
int main()
{
unsigned seed;
//int = rand();
cout << "Enter a seed value: " ;
cin  >> seed;

srand ( time ( 0 ) );
int one = rand() % 500;
int two = rand() % 500;

int sum = one + two;

cout << one << endl << two << endl;
cout << "What are the sum of the two numbers? " ;

if ( herAnswer == sum )
{
cout << "you are correct";
}
else
cout << "naya you are a dummy";
cin.get();
cin.get();
return 0;
}``````

No, I am not a dummy (LOL)

And thank you so much...for the scolding too on the other program. I am currently working on that one. When I get it, I'll come back and show you.

Why are you asking for a seed value? And why are you not using it?

Would be possible to have a program in C (not C++) that create and that add two random generated numbers?

commented: Yes. +15
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.