sum and products

Why don't my sum and products output correctly?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
  #include <iostream>
using namespace std;

int main() {
   int userNum = 0;
   int squaredNum = 0;
   int cubedNum = 0;
   int userNum2 = 0;
   int sumOfNum = 0;
   int productOfNum = 0;

   cout << "Enter integer: ";
   cin  >> userNum;
   cout << endl;
   
   squaredNum = userNum * userNum;
   cubedNum = squaredNum * userNum;
   sumOfNum = userNum + userNum2;
   productOfNum = userNum * userNum2;
   
   cout << "You entered: " << userNum << endl;
   cout << userNum << " squared is " << squaredNum << endl;
   cout << "And "<< userNum << " cubed is "<< cubedNum << "!!"<< endl;
   
   cout << "Enter another integer: ";
   cin >> userNum2;
   cout << endl;
   
   cout << userNum << " + " << userNum2 << " is " << sumOfNum << endl;
   cout << userNum << " * " << userNum2 << " is " << productOfNum << endl;
   
   return 0;
}
rantiv,

Move lines 18 and 19 to after line 27. As is you are trying to get the sumOfNum with userNum2 having a value of zero. Also the same for productOfNum.

My thought with out testing, but should make a big difference.

Hope that helps,

Andy
closed account (GwU9E3v7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
using namespace std;

int main() {
   int userNum = 0;
   int squaredNum = 0;
   int cubedNum = 0;
   int userNum2 = 0;
   int sumOfNum = 0;
   int productOfNum = 0;

   cout << "Enter integer: ";
   cin  >> userNum;
   cout << endl;
   
   squaredNum = userNum * userNum;
   cubedNum = squaredNum * userNum;
   
   cout << "You entered: " << userNum << endl;
   cout << userNum << " squared is " << squaredNum << endl;
   cout << "And "<< userNum << " cubed is "<< cubedNum << "!!"<< endl;
   
   cout << "Enter another integer: ";
   cin >> userNum2;
   cout << endl;
   
   sumOfNum = userNum + userNum2;
   productOfNum = userNum * userNum2;
   
   cout << userNum << " + " << userNum2 << " is " << sumOfNum << endl;
   cout << userNum << " * " << userNum2 << " is " << productOfNum << endl;
   
   return 0;
}


It works and I just did what Andy wanted to do.

but i still tried to figure it out myself.

this is the good code you want.
Thank you BOTH!!
closed account (GwU9E3v7)
:) you are wlecome.

though i do want to know WHY you want to make this thing.

you don't have to tell me but i DO want to know
It was just a challenge activity for Intro to programming. They asked us to create a program that received that input and output those sentences.
Topic archived. No new replies allowed.