can someone point out the mistake in my c++ program. i keep getting error c2240 "cannot convert from void to double"
#include <iostream> using namespace std; void consoleUI(); //prototype header void main() { consoleUI(); //call function } //prototypes void calcPaint(int, int, double&); void calcHours(int, double, double&); void calcPcost(double, double, double&); void calcLabor(double, double, double&); void calcTotal(double, double, double&); void consoleUI() { int r, sqft; double paint; do { cout<<"Enter Number of Rooms: "; cin>>r; } while (r<1); do { cout<<"Enter Price of Paint Per Gallon: $"; cin>>paint; } while (paint<10.00); do { cout<<"Enter Square Feet: "; cin>>sqft; } while (sqft<0); int ft=115, l=8; double labor=18.00, p=0.00, h=0.00, pc=0.00, L=0.00, t=0.00; double gal, hours, pcost, costLabor, total; gal= calcPaint(sqft, ft, p); hours= calcHours(l, gal, h); pcost= calcPcost(gal, paint, pc); costLabor= calcLabor(hours, labor, L); total= calcTotal(pcost, costLabor, t); cout<<"Gallons of Paint Required: "<<gal<<endl <<"Hours of Labor: "<<hours<<endl <<"Paint Cost: "<<pcost<<endl <<"Labor Charge: "<<costLabor<<endl <<"Total Cost of Paint Job: "<<total<<endl; } void calcPaint(int sqft, int ft, double& p) { p= sqft/ft; } void calcHours(int l, double gal, double& h) { h= l*gal; } void calcPcost(double gal, double paint, double& pc) { pc=gal*paint; } void calcLabor(double hours, double labor, double& L) { L=hours*labor; } void calcTotal(double pcost, double costLabor, double& t) { t=pcost+costLabor; }
I believe that the prototypes should be before main(). FWIW, I don't understand the conditions in the while statements.
ohhh let me see. and its input validation cause paint price cant be more than ten dollars and square feet cant be negative, as per the assignment.
still build error with the prototypes before main.
hulppp.
sqft is evaluated in a while statement without having a value assigned to it in consoleUI. gal= calcPaint(sqft, ft, p); hours= calcHours(l, gal, h); pcost= calcPcost(gal, paint, pc); costLabor= calcLabor(hours, labor, L); total= calcTotal(pcost, costLabor, t); are all called assigning the return value of void functions. They're probably the culprits.
ahh so true. now to figure out how to fix it.
the calcX functions are all defined as void. they all expect to set the result in a reference variable passed into them.
the last parameter of each of the calcX methods receive the result of the calculation.
i dont understand how to fix it!
so, for example, instead of: gal= calcPaint(sqft, ft, p); you need to do: calcPaint(sqft, ft, gal);
ah okayy. and then just make p the cout?
another way would be to change all the calX methods so that they return the result instead. e.g.: void calcPaint(int sqft, int ft, double& p) { p= sqft/ft; } would become: double calcPaint(int sqft, int ft) { return sqft/ft; }
this would then be used as: gal= calcPaint(sqft, ft);
#include <iostream> using namespace std; void calcPaint(int, int, double&); void calcHours(int, double, double&); void calcPcost(double, double, double&); void calcLabor(double, double, double&); void calcTotal(double, double, double&); void consoleUI() { int r, sqft; double paint; cout<<"Enter Number of Rooms: "; cin>>r; cout<<"Enter Price of Paint Per Gallon: $"; cin>>paint; cout<<"Enter Square Feet: "; cin>>sqft; if (r>11 && paint>10.00 && sqft>0) { int ft=115, l=8; double labor=18.00, p=0.00, h=0.00, pc=0.00, L=0.00, t=0.00; calcPaint(sqft, ft, p); calcHours(l, p, h); calcPcost(p, paint, pc); calcLabor(h, labor, L); calcTotal(pc, L, t); cout<<"Gallons of Paint Required: "<<p<<endl <<"Hours of Labor: "<<h<<endl <<"Paint Cost: "<<pc<endl <<"Labor Charge: "<<L<<endl <<"Total Cost of Paint Job: "<<t<<endl; } else { cout<<"Error!"<<endl; } } void calcPaint(int sqft, int ft, double& p) { p= sqft/ft; } void calcHours(int l, double p, double& h) { h= l*p; } void calcPcost(double p, double paint, double& pc) { pc=p*paint; } void calcLabor(double h, double labor, double& L) { L=h*labor; } void calcTotal(double pc, double &L, double& t) { t=pc+L; }
now its saying there is a mismatch in formal parameter list at <<"Labor Charge: "<<L<<endl
neverminds got itttt.
Join our real-time social learning platform and learn together with your friends!