print solution (new to C) -
i cant figure out why program wont print final solution (totaldough). inputs 8,10,12 40,100 , 200:
const int dough_per_sqft = 0.75; const int inches_per_feet = 12; #define m_pi 3.14159265358979323846 int main(){ // declare , initialize variables int smallrin; printf("what radius of small pizza, in inches?\n"); scanf("%d", &smallrin); int mediumrin; printf("what radius of medium pizza, in inches?\n"); scanf("%d", &mediumrin); int largerin; printf("what radius of large pizza, in inches?\n"); scanf("%d", &largerin); // number of pizzas sold int smallsold; printf("how many small pizzas expect sell week?\n"); scanf("%d", &smallsold); int mediumsold; printf("how many medium pizzas expect sell week?\n"); scanf("%d", &mediumsold); int largesold; printf("how many large pizzas expect sell week?\n"); scanf("%d", &largesold); // convert radii feet double smallrfeet, mediumrfeet, largerfeet; smallrfeet = smallrin/inches_per_feet; mediumrfeet = mediumrin/inches_per_feet; largerfeet = largerin/inches_per_feet; // calculate top surface areas of each type of pizza. double areasmall, areamedium, arealarge; areasmall = smallsold*m_pi*pow(smallrfeet,2); areamedium = mediumsold*m_pi*pow(mediumrfeet,2); arealarge = largesold*m_pi*pow(largerfeet,2); // print solution double dough; dough = areasmall+areamedium+arealarge; double total_dough; total_dough = dough * dough_per_sqft; printf("the total amount of dough need order week is", total_dough); return 0; }
what doing wrong?
const int dough_per_sqft = 0.75;
this of value int , int's not floating-point numbers, translates to:
0
this means in final equation
total_dough = dough * dough_per_sqft;
it evaluate 0 because dough per sqft equal 0.
this can corrected changing:
const int dough_per_sgft = 0.75
into:
const double dough_per_sgft = 0.75
Comments
Post a Comment