I need Help writing my code...Please


#include<iostream>

using namespace std;
int main()

{
double lenghtft;
double lenghtin;
double thickft;
double thickin;
double widthft;
double widthin;
double lenght;
double width;
double thickness;
double volume;
double weight;

cout << "Program to calculate the Volume of a concrete slab and "
<< "output the average weight of the slab." << endl;

length = 6'0;
width = 8'0;
thickness = 0.8;
Volume = length * width * thickness;
weight = Volume -150;


cout << "Length = " << length << endl;
cout << "Width = " << width << endl;
cout << "thickness = " << thickness << endl;
cout << "Volume = " << Volume << endl;
cout << "weight = " << weight << endl;

return 0;
}

Somehow the output value must be, i have no idea every time i make a breakthrough i get errors in my code :(
lenght = 6'0
width = 8'0
thickness = 0.8
volume = 31.872
weight = 4700.0
closed account (2LzbRXSz)
Your code has multiple typos (which, assuming this is your code and not homework, your compiler should detect for you), so let's take it step-by-step:)

double lenght;

Is misspelled, throwing off most of the code.

Volume = length * width * thickness;

weight = Volume -150;

C++ is case-sensitive. You have volume declared with a lower case v...

double volume;

Either change this, or fix the other calls to the variable.

1
2
    length = 6'0;
    width = 8'0;

You have them defined as doubles, so I'm just going to assume this is supposed to be 6.0 and 8.0. Get rid of the apostrophe, and replace it with a period.

Other than that, I think it's okay. You could also define all those doubles like...
double lenghtft, lenghtin, thickft, thickin, widthft, widthin, length, width, thickness, volume, weight;
But that's more for style preference.
Last edited on
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
35
36
#include<iostream>

using namespace std;

int main()
{
double lenghtft;
double lenghtin;
double thickft;
double thickin;
double widthft;
double widthin;
double lenght;
double width;
double thickness;
double volume;
double weight; 

cout << "Program to calculate the Volume of a concrete slab and "
<< "output the average weight of the slab." << endl;

length = 6'0;
width = 8'0;
thickness = 0.8; 
Volume = length * width * thickness;
weight = Volume -150;


cout << "Length = " << length << endl;
cout << "Width = " << width << endl;
cout << "thickness = " << thickness << endl;
cout << "Volume = " << Volume << endl;
cout << "weight = " << weight << endl; 

return 0;
}
Topic archived. No new replies allowed.