Here is my program it works how I would like it to but I can't seem to get formatting down. I want to round the numbers off in the dollar output. In some cases it is giving me 3 numbers in the cents column. I know there is a way to do it using floats but I can't seem to find the info on how to do it. My book isn't much help. Also in a couple cases I am setting a variable from another and I am unsure how to use ( char variable[25] ). You can see some of my variables have pointers and my teacher doesn't want me to use them yet. Thanks in advance.
Code:#include <iostream> #include <iomanip> using namespace std; const double RED_RUG = 4.99; const double GREEN_RUG = 5.99; const double BLUE_RUG = 6.99; int main(void) { char* discount; char customerName[25]; char rugColor; char paymentMethod; int roomLength; int roomWidth; //variables char* rugDisplay; char* discountPercent; int roomArea; double endDiscount; double paidDiscount; double rugCost; double carpetCost; double trueCost; cout<<setw(20)<<"Welcome to..."<<endl; cout<<endl; cout<<setw(40)<<">>>Phils Floors<<<<"<<endl; //business header-output to screen cout<<endl; cout<<setw(37)<<"Our Rugs Rock"<<endl; cout<<endl; cout<<"If you enter the customers name, type of rug purchased,"<<endl; cout<<"room dimensions, and type of payment, this program"<<endl; //program explaination cout<<"will calculate and print a bill to the screen"<<endl; cout<<endl; cout<<"Please enter the customers name: "; cin.getline(customerName,25); //input customers name cout<<endl; cout<<"Please enter rug color (R)ed (B)lue (G)reen: "; cin>>rugColor; //input rug color cout<<endl; if (rugColor == 'R' || rugColor == 'r') { rugDisplay = "RED"; rugCost = RED_RUG; } else if (rugColor == 'B' || rugColor == 'b') { rugDisplay = "BLUE"; //set rugdisplay variable and cost of rug rugCost = BLUE_RUG; } else if(rugColor == 'G' || rugColor == 'g') { rugDisplay = "GREEN"; rugCost = GREEN_RUG; } else { rugDisplay = "N/A"; rugCost = 6.99; } cout<<endl; cout<<"Please enter the method of payment"<<endl; cout<<"(C)ash (Z)ippy or (O)ther: "; cin>>paymentMethod; //input payment method if (paymentMethod == 'C' || paymentMethod == 'c') paidDiscount = .10; else if (paymentMethod == 'Z' || paymentMethod == 'z') //set paidDiscount variable to use in calculation paidDiscount = .05; else paidDiscount = 1; if (paymentMethod == 'C' || paymentMethod == 'c') { discount = "Cash and Carry"; discountPercent = "10% -- Cash and Carry"; } else if (paymentMethod == 'Z' || paymentMethod == 'z') { discount = "Zippy Discount"; //set discount variables (output messages) discountPercent = "5% -- Zippy Discount"; } else if (paymentMethod == 'O' || paymentMethod == 'o') { discount = "No Discount"; discountPercent = "No Discount"; } else discount = "No discount type specified"; cout<<endl; cout<<"Enter the Length of your room: "; //input room length cin>>roomLength; cout<<endl; cout<<"Enter the Width of your room: "; cin>>roomWidth; //input room width roomArea = (roomWidth * roomLength); //calculate room area carpetCost = (roomArea * rugCost); //calculate rug cost endDiscount = (roomArea * rugCost * paidDiscount); //calculate discount trueCost = (carpetCost - endDiscount); //calculate carpet cost minus the discount (truecost) cout<<setw(40)<<">>>Phil's Floors<<<<"<<endl; cout<<endl; //output header cout<<setw(37)<<"Our Rugs Rock"<<endl; cout<<endl; cout<<"Customer Name:"<<setw(26)<<customerName<<endl; //output customer name cout<<endl; cout<<"Rug Color:"<<setw(30)<<rugDisplay<<endl; //output rugcolor cout<<endl; cout<<"Payment Method:"<<setw(25)<<discount<<endl; //output payment method cout<<endl; cout<<setw(30)<<discountPercent<<endl; //output discount percent message cout<<endl; cout<<"Discount: "<<setw(26)<<"$"<<endDiscount<<endl; //output discount cout<<endl; cout<<"Rug Cost: "<<setw(25)<<"$"<<carpetCost<<endl; //output carpet cost (before discount) cout<<"Final Cost:"<<setw(24)<<"$"<<trueCost<<endl; //output carpet cost(final cost-after discount) return 0;



LinkBack URL
About LinkBacks


