•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 455,968 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,746 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 533 | Replies: 3 | Solved
![]() |
•
•
Join Date: Nov 2007
Posts: 21
Reputation:
Rep Power: 1
Solved Threads: 0
I am writing a program that generates 2 random #'s then asks the user to give the product of the 2. I have everything (close to) working except the input. I even added a "cheat" to display the answer
Thanks for your help, this is due in like an hour so I am trying to finish it up.
prod and when inputting the exact same #, it is registering as incorrect.Thanks for your help, this is due in like an hour so I am trying to finish it up.
int main ()
{
int a, wrong, right;
int count = 0;
int count2 = 0;
int num1, num2, prod;
srand (time(0));
wrong = 0;
right = 0;
cout << "Multiplication\n" << "ctrl-z to quit\n";
while (count <= 11)
{
count++;
if (count >= 10)
{
count2 = count2 + count;
count = 0;
}
randomGen (&num1, &num2);
prod = num1 * num2;
cout << "What is " << num1 << " times " << num2 << endl;
cin >> a;
counter (&count, &count2, &wrong, &right);
while (!cin.eof() || a != prod)
{
cout << prod;
incorrect ();
wrong++;
cin >> a;
}
if (a == prod)
{
correct();
right++;
}
}
}•
•
Join Date: Nov 2007
Posts: 21
Reputation:
Rep Power: 1
Solved Threads: 0
here is the rest of the code, I just posted the relevant sections. That's why you got the errors.
Thanks
Thanks
int randomGen (int *num1, int *num2)
{
*num1 = rand () % 10;
*num2 = rand () % 10;
return *num1, *num2;
}
void correct()
{
int x;
srand (time(0));
x = rand () % 5;
switch (x)
{
case 1:
cout << "\nGreat!" << endl;
break;
case 2:
cout << "\nCorrect!" << endl;
break;
case 3:
cout << "\nYou got it!" << endl;
break;
case 4:
cout << "\nGood job" << endl;
break;
case 5:
cout << "\nYay!" << endl;
}
}
void incorrect()
{
int x;
srand (time(0));
x = rand () % 5;
switch (x)
{
case 0:
case 1:
cout << "\nWrong!" << endl;
break;
case 2:
cout << "\nNo!" << endl;
break;
case 3:
cout << "\nDunce!" << endl;
break;
case 4:
cout << "\nGive it another shot" << endl;
break;
case 5:
cout << "\nOops!" << endl;
}
}
void counter (int *count, int *count2, int *wrong, int *right)
{
if (*count2 >= 10 && *count2 % 10 == 0)
{
cout << setw(10) << "Wrong " << setw(10) << " Right " << setw(10) << " Total\n"
<< setw(10) << *wrong << setw(10) << *right << setw(10) << *wrong + *right << endl;
}
}•
•
Join Date: Aug 2007
Location: South Dakota
Posts: 980
Reputation:
Rep Power: 6
Solved Threads: 97
while (!cin.eof() || a != prod)
remember that the modulus operator (%) will give results in the range 0-(divisor -1) - check your switches, and the values you are generating for the multiplicands.
srand( ) need only be called once in your program - main( ) should call it early on.
your outer while loop should also check for eof( ) for the program to end correctly.
that should be enough to keep you busy for a while.
Val
I am in mourning for my country.
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- switching input from one rs232 port to another (C)
- ASM Problem[Please help me] (Assembly)
- Shellprogramming-help needed (Shell Scripting)
- on a simple airline booking program (C)
- Positive and negative numbers (C++)
- is there anyway my program can recognize words (C++)
- how to override arrays and objects??? (Java)
- transfer input.txt to output.txt help prz (C++)
- in need of some hw help (C++)
Other Threads in the C++ Forum
- Previous Thread: help....errors in program
- Next Thread: cin.ignore() ??????


Linear Mode