943,724 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 27806
  • C++ RSS
Mar 21st, 2004
0

multiplication tutorial

Expand Post »
i am in a class and find C++ a challenge. i have an assignment and this is what i have so far. i need help, because i am not too analytical.


#include <cstdlib>
#include <ctime>
#include <iostream>
using std::cout;
using std::endl;
int main()
{
int (a, b);
int (a * b ) = result;
int result;

srand( (unsigned)time( NULL ) ); //set seed to sys time
for (int i = 1; i < 2; i++)
{
cout << 1 + rand() % (10 - 1 + 1)<< endl;
cout << 1 + rand() % (10 - 1 + 1)<< endl;//how do i put side beside each other with X's sign
}
return 0;
}
cin >> c
if (int a * int b) = int c
getline int c//do i need this
cout << "" ", is the correct answer."

if c != (int a * int c)
getline int c
cout << "" ", is not the correct answer."
// loop to try again
//option to exit either way



Use rand() to produce two positive one-digit integers.
The program should then output a question using the numbers.
The student then types the answer. The program checks the student’s answer.
If it is correct, print “Very good!”, and ask another multiplication question.
If the answer is wrong, print “No. Please try again.”, and let the student
try the same question repeatedly until the student gets it right.

should i use calling or pass by value?
Similar Threads
Reputation Points: 14
Solved Threads: 0
Newbie Poster
popo_prince is offline Offline
12 posts
since Mar 2004
Mar 22nd, 2004
0

Re: multiplication tutorial

my c++ is a little rusty, stupid java!
I don't know what 'calling' is, but you shouldn't need to pass anything.

C++ Syntax (Toggle Plain Text)
  1. DO
  2. int a = some random number
  3. int b = some random number
  4. int product = a*b;
  5. int answer = 0;
  6. bool correct = false;
  7.  
  8. while (!correct)
  9. cout <<"What is "<<a<<" times "<<b<<"?";
  10. cin >> answer;
  11.  
  12. if (answer == product)
  13. correct = true;
  14. else
  15. correct = false;
  16.  
  17. if (!correct)
  18. cout<<"Please try again.";
  19. else
  20. cout<<"Good job!";
  21. LOOP


I think I even mixed BASIC in there as well. You should get the idea though. I think you're trying to make this way more difficult than it needs to be.
Reputation Points: 92
Solved Threads: 51
Practically a Posting Shark
Phaelax is offline Offline
856 posts
since Mar 2004
Mar 22nd, 2004
0

Re: multiplication tutorial

thank you. i forgot about the bolean functions. that will make it easier. it will try to build this and make it work.
thanks phaelax
Reputation Points: 14
Solved Threads: 0
Newbie Poster
popo_prince is offline Offline
12 posts
since Mar 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Help with random number gen
Next Thread in C++ Forum Timeline: C++ Relcat/Attrcat catalog help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC