Error Message for Variables for Program

Pages: 12
The test data I have for the program has listed width has a double variable, but when I try to compile and run the program, I get these 2 messages with the width part highlighted:

expected init-declarator before "double"
expected `,' or `;' before "double"

What do they mean? Is there a problem somewhere else with my code?

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73

// Headers and Other Technical Items

#include <iostream>  
using namespace std;

// Function Prototypes

void pause(void);

// Variables

double       length
double       width
double       height
double       price_gal_paint
int          coverage_gal_paint
double       total_area
int          total_gal_paint
double       total_cost

//******************************************************
// main
//******************************************************

int main(void)
  {
  // Input	
  cout << "\nEnter the length of the house --->: ";
  cin >> lenght;
  cout << "\nEnter the width of the house -->: ";
  cin >> width;
  cout << "\nEnter the height of the house -->: ";
  cin >> height;
  cout << "\Enter the price of a gallon of paint -->: "; 
  cin >> price_gal_paint;
  cout << "\Enter the square feet coverage of a gallon of paint -->: "; 
  cin >> coverage_gal_paint; 
  

  // Process
  
  cout << "\n";
  cout << "\nThe total area of the building is needed ---->: ";
  cout << (double) (length * height * 2) + (width * height * 2);

  pause (); 
   

  cout << "\n";
  cout << "\nThe total gallons of paint is needed ---->: ";
  cout <<  (int) (total_gal_paint = total_area / coverage_gal_paint + 0.9999);

  pause();
  
  cout << "\n"; 
  cout << "\nThe total cost of the paint is needed ---->: "; 
  cout << (double) (total_gal_paint * price_gal_paint);
  
  pause (); 
  
  //Output
  
   cout << "\nThe gallons of paint needed is -------->: ";
  cout << answer;
  
   cout << "\nThe total cost is -------->: ";
  cout << answer;
  
   pause();
  return 0;
  }

After declaring variables you need to put ;
So this is the right way
1
2
3
4
5
6
7
8
double       length;
double       width;
double       height;
double       price_gal_paint;
int          coverage_gal_paint;
double       total_area;
int          total_gal_paint;
double       total_cost;


Or I suggest you to do like this
1
2
double lenght, width, height, price_gal_paint, total_area, total_cost;
int coverage_gal_paint, total_gal_paint;
Last edited on
Thanks! That solved that problem. But I stll can't compile...I still get error messages.
It would help if you would tell the errors.
I was able to compile the code...But I'm not getting the results I should for total cost and total gallons...I just get 0 for both results.

The errors are:

In function `int main()':

[Warning] converting to `int' from `double'


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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79

// Headers and Other Technical Items

#include <iostream>  
using namespace std;

// Function Prototypes

void pause(void);

// Variables

double       length;
double       width;
double       height;
double       price_gal_paint;
int          coverage_gal_paint;
double       total_area;
int          total_gal_paint;
double       total_cost;

//******************************************************
// main
//******************************************************

int main(void)
  {
  // Input	
  cout << "\nEnter the length of the house --->: ";
  cin >> length;
  
  cout << "\nEnter the width of the house --->: ";
  cin >> width;
  
  cout << "\nEnter the height of the house --->: ";
  cin >> height;
  
  cout << "\nEnter the price of a gallon of paint--->: ";
  cin >> price_gal_paint;
  
  cout << "\nEnter the square feet coverage of a gallon of paint --->: ";
  cin >> coverage_gal_paint;
  
  

  // Process
  
  cout << "\n"; 
  cout << "\nThe total cost of the paint is  ---->: "; 
  cout << (double) (total_cost = total_gal_paint * price_gal_paint);
  
  pause (); 
  
  cout << "\n";
  cout << "\nThe total gallons of paint is  ---->: ";
  cout << (int) (total_gal_paint = total_area / coverage_gal_paint + 0.9999);
  
  pause (); 
  
  cout << "\n";
  cout << "\nThe total area of the building is  ---->: ";
  cout << (double) (length * height * 2) + (width * height * 2);

  pause (); 
   
  
  //Output
  
   cout << "\nThe gallons of paint needed is -------->: ";
  cout << total_gal_paint;
  
   cout << "\nThe total cost is -------->: ";
  cout << total_cost;
  
   pause();
  return 0;
  }

Last edited on
Line 50: total_gal_paint has no value.

Line 56: total_area has no value.
Why are you even setting them equal in the output statement?

I would break them apart on lines 50 and 56. Also you don't exactly need to cast those variables they should be fine without.

Ps you error is from the cast on 56.
Last edited on
Do you mean like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15


cout << "\n";
  cout << "\nThe total gallons of paint is  ---->: ";
  cout << (int) (total_area / coverage_gal_paint + 0.9999);
  
  pause (); 
  
  cout << "\n"; 
  cout << "\nThe total cost of the paint is ---->: "; 
  cout << (double) (total_gal_paint * price_gal_paint);
  
  pause (); 
  
?

I still get 0. I have also tried taking away the int and double labels. I got .999 for the total gallons. On that part, I'm suppose to round off.
I don't know then..I what exactly are your fomulas?

is it supposed to be area / ( coverage + .9999 ) ? and anyways why .9999 why not 1?
Oh lol your problem is umm total_area is undefined...I thought you changed that after ccsdude mentioned it.
I still have the same error messages even after fixing it. My reverse IPO comes out right though...Everything seems to work just fine..except for those error messages:

In function `int main()':

[Warning] converting to `int' from `double'

Do I just ignore them or what?

Current code:

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91

// Headers and Other Technical Items

#include <iostream>  
using namespace std;

// Function Prototypes

void pause(void);

// Variables

double       length;
double       width;
double       height;
double       price_gal_paint;
int          coverage_gal_paint;
double       total_area;
int          total_gal_paint;
double       total_cost;

//******************************************************
// main
//******************************************************

int main(void)
  {
  // Input	
  cout << "\nEnter the length of the house --->: ";
  cin >> length;
  
  cout << "\nEnter the width of the house --->: ";
  cin >> width;
  
  cout << "\nEnter the height of the house --->: ";
  cin >> height;
  
  cout << "\nEnter the price of a gallon of paint--->: ";
  cin >> price_gal_paint;
  
  cout << "\nEnter the square feet coverage of a gallon of paint --->: ";
  cin >> coverage_gal_paint;
  
  

  // Process
  
  
  (double) (total_area = length * height * 2 + width * height * 2);

 
  
 (int) (total_gal_paint = total_area / coverage_gal_paint + 0.9999);
  
  
 
 (double) (total_cost = total_gal_paint * price_gal_paint);
  

 
  
  //Output
  
  cout << "\nThe gallons of paint needed is -------->: ";
  cout << total_gal_paint;
  
  cout << "\nThe total cost is -------->: ";
  cout << total_cost;
  
   pause();
  return 0;
  }

//******************************************************
// pause
//******************************************************

void pause(void)
  {
  cout << "\n\n";
  system("PAUSE");
  cout << "\n\n";
  return;
  }

//******************************************************
// End of Program
//******************************************************




The pseudocode was given to me:

input
display a message asking user for the length of the house
get the length of the house from the keyboard
display a message asking user for the width of the house
get the width of the house from the keyboard
display a message asking user for the height of the house
get the height of the house from the keyboard
display a message asking user for the price of a gallon of paint
get the price of a gallon of paint from the keyboard
display a message asking user for the sq ft coverage of a gallon of paint
get the sq ft coverate of a gallon of paint from the keyboard

processing
calculate the total area of the building by:
1) multiplying the length by height by 2;
2) then multiply the width by height by 2;
3) then add the two results together
calculate the number of gallons of paint needed by:
1) dividing the total area by the coverage per gallon;
2) and then round up to the next whole gallon
calculate the total cost of the paint by:
1) multiplying the total gallons needed by the price of one gallon of paint

output
display the total gallon of paint needed with an appropriate message
display the total cost with an appropriate message
pause so the user can see the answer

******************************************************

Potential Variables

Data Type Identifier Name
********* ***************
double length
double width
double height
double price_gal_paint
int coverage_gal_paint
double total_area
int total_gal_paint
double total_cost
Last edited on
closed account (28poGNh0)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Headers and Other Technical Items

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

// Function Prototypes

void pause(void);

// Variables

double       length;
double       width;
double       height;
double       price_gal_paint;
int          coverage_gal_paint;
double       total_area;
int          total_gal_paint;
double       total_cost;

//******************************************************
// main
//******************************************************

int main(void)
{
    // Input
    cout << "\nEnter the length of the house --->: ";
    cin >> length;

    cout << "\nEnter the width of the house --->: ";
    cin >> width;

    cout << "\nEnter the height of the house --->: ";
    cin >> height;

    cout << "\nEnter the price of a gallon of paint--->: ";
    cin >> price_gal_paint;

    cout << "\nEnter the square feet coverage of a gallon of paint --->: ";
    cin >> coverage_gal_paint;

    // Process
    total_area = length * height * 2 + width * height * 2;

    total_gal_paint = total_area / coverage_gal_paint + 0.9999;

    total_cost = total_gal_paint * price_gal_paint;

    //Output
    cout << "\nThe gallons of paint needed is -------->: ";
    cout << total_gal_paint;

    cout << "\nThe total cost is -------->: ";
    cout << total_cost;

    pause();

    return 0;
}

//******************************************************
// pause
//******************************************************

void pause(void)
{
    cout << "\n\n";
    system("PAUSE");
    cout << "\n\n";

    return;
}

//******************************************************
// End of Program
//****************************************************** 
Hi. I made the changes you suggested. I'm still getting those errors.

In function `int main()':


[Warning] converting to `int' from `double' <--- this error points to this line:


total_gal_paint = total_area / coverage_gal_paint + 0.9999;

I am suppose to round off. I was told to do so. When I run the program, I get the results I should.

length=100
w=40
h=10
price of gallon of paint= 28.49
coverage gallon of paint = 250

outputs should be (and are)

total gallon paint = 12
total cost= 341.88


The problem is that total_gal_paint is an int, and you are assigning a double to it.

If you are meant to do it, then it is no problem. Warnings are not errors.

BTW, glad to see a new member!
Last edited on
You can show in code that you "know what you are doing"TM:
total_gal_paint = static_cast<int>( total_area / coverage_gal_paint + 0.9999 );
Thanks! I still haven't learn about static_cast, but I will use it.

As a final question, in my original code I had this:

1
2
3
4

#include <iostream> 
using namespace std;


And Techno01 changed it to:

1
2
3
4
5
6

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



Why? My outputs didn't change.
You don't need cstdlib.
closed account (28poGNh0)
@Superdude
You don't need cstdlib.
why?

int system(const char*); is a function provided by the cstdlib library, that's why we need to include it .

but there is some compilators dont ask for some function's header including ,maybe internaly it inlucdes theme !
You mean in his pause function? He doesn't need to use system. Just use this.
1
2
3
4
5
6
7
8
void pause()
{
      cout << "\n\n"; //Whatever that is for
      cout << "Press ENTER to continue";
      cin.get(); //Or cin.ignore('\n'); whatever
      cout << "\n\n";
}


Last edited on
closed account (28poGNh0)
In this case yes ,but he implemented its pause() function like this

1
2
3
4
5
6
7
8
void pause(void)
{
    cout << "\n\n";
    system("PAUSE");
    cout << "\n\n";

    return;
}


thats why I included <cstdlib> header
Pages: 12