I having some trouble with my if statement would someone help me outmain.cppCode:#include<stdio.h> void main() { char instruc[2]; const double artichokes=1.25,beets=0.65,carrots=0.89,discount=0.05; double totalartichokes,totalbeets,totalcarrots,totalpound=0,shipping,input,totalcost,pounds; bool keepgoing =true;// a bolean data type printf("\n"); printf(" ABC Mail Order Grocery\n\n"); printf(" Type 'a' for artichokes, 'b' for beets, 'c' for carrots , and 'q' to exit sale.\n\n"); //frist we need an infinite loop while (1){// 1 is always logicaly true //next we will read an instruction from stdio scanf("%s %lf",instruc, &input); switch(instruc[0]) { case 'a': pounds+=input; totalartichokes=artichokes*input; printf(" Artichokes %lf\n", totalartichokes); break; case 'b': pounds+=input; totalbeets=beets * input; printf(" beets %lf\n", totalbeets); break; case 'c': pounds+=input; totalcarrots=carrots * input; printf(" carrots %lf\n", totalcarrots); break; case 'd': totalpound+=pounds; totalcost= totalartichokes+totalbeets+totalcarrots ; printf("\n Total Weight is %.2lf",totalpound); printf("\n SubTotal is $%.2lf \n",totalcost); if(totalcost>= 100) totalcost=totalcost-(.05*totalcost); if(totalpound >= 5) totalcost=3.50+totalcost;// $3.50 shipping shipping=3.50; if(totalpound <= 5 ) if(totalpound>=20) totalcost=10.00+totalcost;// $10.00 over 5pounds ,but under 20pounds shipping shipping=10.00; if(totalpound < 20) totalcost=8.00+(.10*totalpound)+totalcost; shipping=8.00+(.10*totalpound); break; case 'q': keepgoing = false; break; {printf(" Shipping and handling is $%.2lf\n",shipping); printf("\n Total is $%.2lf \n",totalcost);} }// end switch(instruc[0]) if (keepgoing==false)break; // exit the infinite loop }//end while (1) loop }//end main



LinkBack URL
About LinkBacks



