| micahcujo (3) | |
|
Hi i am making a program that will ask the user to enter in a price for the days that they shopped on the 12 days of xmas. my question is, what if the user did not shop on day 5, but shopped on day 1 and 2. i have tried if statements and when i do it just spits out the rest of my code and says "this day cannot be initialized". here is my code. i would like to know how to input a default value so it can add up all the numbers entered. i am a beginner #include <iostream> #include<cmath> using namespace std; int main() { //Declare Variables float PatridgeTree = 204.99 *1; float TwoTurtle = 125 *2; float ThreeHens = 165 *3; float FourBirds = 519.96 *4; float FiveRings = 750 *5; float SixGeese = 210 *6; float SevenSwans = 7000 *7; float EightMaids = 58 *8; float NineLadies = 6294 *9; float TenLords = 4767 *10; float ElevenPipers = 2562 *11; float TwelveDrummers = 2776 *12; float total; //Declare Your Variables float YOURpatridgetree; float YOURTwoTurtle; float YOURThreeHens; float YOURFourBirds; float YOURFiveRings; float YOURSixGeese; float YOURSevenSwans; float YOUREightMaids; float YOURNineLadies; float YOURTenLords; float YOURElevenPipers; float YOURTwelveDrummers; float YOURtotal; cout << "12 DAYS OF CHRISTMAS!" << endl; cout << "--------------------------"<< endl; system ("pause"); cout << endl; cout << "Drummers = $2,776. Pipers = $2,562. Lords = $4,767. Ladies = $6,294." << endl; cout << "Maides = $58. Swans = $7,000. Geese = $210. Rings = $750." << endl; cout << "Birds = $519.96. Hens = $165. Turtles = $125." << endl; cout << "Pear tree and Patridge = $204.99." << endl << endl; system ("pause"); cout << endl << "Day 1) 1* Patridge Tree"; cout << endl << "\t= $" << PatridgeTree << endl; cout << "\tEnter Your Price" << endl; cout << "\t= $"; cin >> YOURpatridgetree; cout << endl << "Day 2) 2* Turtles + 1* PatridgeTree"; cout << endl << "\t= $" << TwoTurtle + PatridgeTree << endl; cout << "\tEnter Your Price" << endl; cout << "\t= $"; cin >> YOURTwoTurtle; cout << endl << "Day 3) 3* Hens + 2* Turtles + 1* PatridgeTree"; cout << endl << "\t= $" << ThreeHens + TwoTurtle + PatridgeTree << endl; cout << "\tEnter Your Price" << endl; cout << "\t= $"; cin >> YOURThreeHens; cout << endl << "Day 4) 4* Birds 3* Hens + 2* Turtles + 1* PatridgeTree"; cout << endl << "\t= $" << FourBirds + ThreeHens + TwoTurtle + PatridgeTree << endl; cout << "\tEnter Your Price" << endl; cout << "\t= $"; cin >> YOURFourBirds; cout << endl << "Day 5) 5* Rings 4* Birds 3* Hens + 2* Turtles + 1* PatridgeTree"; cout << endl << "\t= $" << FiveRings + FourBirds + ThreeHens + TwoTurtle + PatridgeTree << endl; cout << "\tEnter Your Price" << endl; cout << "\t= $"; cin >> YOURFiveRings; cout << endl << "Day 6) 6* Geese 5* Rings 4* Birds 3* Hens + 2* Turtles + 1* PatridgeTree"; cout << endl << "\t= $" << SixGeese + FiveRings + FourBirds + ThreeHens + TwoTurtle + PatridgeTree << endl; cout << "\tEnter Your Price" << endl; cout << "\t= $"; cin >> YOURSixGeese; cout << endl << "Day 7) 7* Swans 6* Geese 5* Rings 4* Birds 3* Hens + 2* Turtles"; cout << endl << "\t+ 1* PatridgeTree"; cout << endl << "\t= $" << SevenSwans + SixGeese + FiveRings + FourBirds + ThreeHens + TwoTurtle + PatridgeTree << endl; cout << "\tEnter Your Price" << endl; cout << "\t= $"; cin >> YOURSevenSwans; cout << endl << "Day 8) 8* Maids 7* Swans 6* Geese 5* Rings 4* Birds 3* Hens + 2* Turtles"; cout << endl << "\t+ 1* PatridgeTree"; cout << endl << "\t= $" << EightMaids + SevenSwans + SixGeese + FiveRings + FourBirds + ThreeHens + TwoTurtle + PatridgeTree << endl; cout << "\tEnter Your Price" << endl; cout << "\t= $"; cin >> YOUREightMaids; cout << endl << "Day 9) 9* Ladies 8* Maids 7* Swans 6* Geese 5* Rings 4* Birds 3* Hens"; cout << endl << "\t+ 2* Turtles + 1* PatridgeTree"; cout << endl << "\t= $" << NineLadies + EightMaids + SevenSwans + SixGeese + FiveRings + FourBirds + ThreeHens + TwoTurtle + PatridgeTree << endl; cout << "\tEnter Your Price" << endl; cout << "\t= $"; cin >> YOURNineLadies; cout << endl << "Day 10) 10* Lords 9* Ladies 8* Maids 7* Swans 6* Geese 5* Rings 4* Birds"; cout << endl << "\t3* Hens + 2* Turtles + 1* PatridgeTree"; cout << endl << "\t= $" << TenLords + NineLadies + EightMaids + SevenSwans + SixGeese + FiveRings + FourBirds + ThreeHens + TwoTurtle + PatridgeTree << endl; cout << "\tEnter Your Price" << endl; cout << "\t= $"; cin >> YOURTenLords; cout << endl << "Day 11) 11* Pipers 10* Lords 9* Ladies 8* Maids 7* Swans 6* Geese 5* Rings"; cout << endl << "\t4* Birds 3* Hens + 2* Turtles + 1* PatridgeTree"; cout << endl << "\t= $" << ElevenPipers + TenLords + NineLadies + EightMaids + SevenSwans + SixGeese + FiveRings + FourBirds + ThreeHens + TwoTurtle + PatridgeTree << endl; cout << "\tEnter Your Price" << endl; cout << "\t= $"; cin >> YOURElevenPipers; cout << endl << "Day 12) 12* Drummers 11* Pipers 10* Lords 9* Ladies 8* Maids 7* Swans 6* Geese"; cout << endl << "\t5* Rings 4* Birds 3* Hens + 2* Turtles + 1* PatridgeTree"; cout << endl << "\t= $" << TwelveDrummers + ElevenPipers + TenLords + NineLadies + EightMaids + SevenSwans + SixGeese + FiveRings + FourBirds + ThreeHens + TwoTurtle + PatridgeTree << endl; cout << "\tEnter Your Price" << endl; cout << "\t= $"; cin >> YOURTwelveDrummers; total = PatridgeTree + TwoTurtle + ThreeHens + FourBirds + FiveRings + SixGeese + SevenSwans + EightMaids + NineLadies + TenLords + ElevenPipers + TwelveDrummers; YOURtotal = YOURpatridgetree + YOURTwoTurtle + YOURThreeHens + YOURFourBirds + YOURFiveRings + YOURSixGeese + YOURSevenSwans + YOUREightMaids + YOURNineLadies + YOURTenLords + YOURElevenPipers + YOURTwelveDrummers;; cout << endl << "Total Price of 12 Days:" << endl; cout << "\t=" << total << endl; cout << endl << "Your Total Price of 12 Days:" << endl; cout << "\t=" << YOURtotal << endl << endl; return 0; } | |
|
Last edited on
|
|
| SamuelAdams (192) | |||
|
I'm not sure what your asking, when I type 1 or 0 for any cin input, it seems to work for me. you might try float YOURpatridgetree=0;If your checking for a <Enter> being typed in, you may need to create
| |||
|
|
|||
| micahcujo (3) | |
|
Thank you for responding. For example after the day 1. cout << endl << "Day 1) 1* Patridge Tree"; cout << endl << "\t= $" << PatridgeTree << endl; cout << "\tEnter Your Price" << endl; cout << "\t= $"; cin >> YOURpatridgetree; //would i put an if statement here? Before I had, cout << endl << "Day 1) 1* Patridge Tree"; cout << endl << "\t= $" << PatridgeTree << endl; cout << "\tEnter Your Price By pressing 1, otherwise press 2 to continue" << endl; int answer; If (answer ==1) cout << "\tEnter Your Price" << endl; cout << "\t= $"; cin >> YOURpatridgetree; If (answer ==2) // can you help me with the default value here? // or is there a command that the user just presses enter after he inputs a 2? //This is were i was stuck, i want to input the default value of 0 and then continue on to day 2. and ask the same question for day 2. | |
|
|
|