fork download
  1. // Cenyao Huang CS1A Chapter 3, P. 146, #15
  2. /************************************************************************
  3. * TUTORING MATH
  4. * This program tutors students.
  5. *
  6. * Input
  7. * num1 : the value of the first number
  8. * num2 : the value of the second number
  9. *
  10. * Output
  11. * ans : the answer to num1 + num2
  12. ************************************************************************/
  13.  
  14. #include <iostream>
  15. #include <cstdlib>
  16. #include <string>
  17. using namespace std;
  18.  
  19. int main() {
  20. int num1, num2, ans; // assign data type to variable
  21.  
  22. srand(time(0)); // get two random numbers
  23. num1 = rand() % 100 + 399;
  24. num2 = rand() % 100 + 399;
  25.  
  26. cout << " " << num1 << endl << "+ " << num2 << endl << "-----" << endl << endl; // display math problem
  27.  
  28. ans = num1 + num2; // compute math problem
  29.  
  30. cout << " " << num1 << endl << "+ " << num2 << endl << "_____" << endl << " " << ans;
  31. // display answer to math problem
  32.  
  33. return 0;
  34. }
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
  421
+ 470
-----

  421
+ 470
_____
  891