What am I doing wrong...

#include <iostream>
#include <cmath>
using namespace std;




int main()
{

int length;
int width;
int depth;
int total;

total = length * width * depth;
cout << "Enter Length: ";
cin >> length;

cout << "Enter Width: ";
cin >> width;

cout << "Enter Depth: ";
cin >> depth;



cout << "total is: " << total;
}
system("pause");
return(0);
You calculate total before you allow the user to enter values for length, width and depth! Try this one:

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
#include <iostream>
#include <cmath> //<- this is not necessary
using namespace std;

int main()
{
     int length;
     int width;
     int depth;
     int total;

     cout << "Enter Length: ";
     cin >> length;

     cout << "Enter Width: ";
     cin >> width;

     cout << "Enter Depth: ";
     cin >> depth;

     //move the line you calculate total here!
     total = length * width * depth;

     cout << "total is: " << total << endl;

     system("pause");
     return 0;
}

Last edited on
Topic archived. No new replies allowed.