Как я могу отобразить общую цену после первой покупки и других puchases
я хочу отобразить общую цену для первой покупки, но в то же время эта общая цена все еще отображается на экране, когда я хочу купить другой товар. после того, как я закончу покупать все предметы, которые мне нужны, я хочу суммировать их, чтобы получить окончательную стоимость моей покупки. мне действительно нужна ваша помощь, ребята . Спасибо!!
Что я уже пробовал:
#include <iostream> #include <stdlib.h> #include <string> using namespace std; int main() { void totalPrice1( int , int& , int&); void totalPrice2( int , int& , int& ); void totalPrice3( int , int& , int& ); void totalPrice4( int , int& , int& ); void name(); void menu(); void read( int&); void totalPrice5( int , int& ); void totalPrice6( int , int& ); void totalPrice7( int , int& ); void totalPrice8( int , int& ); void totalPrice9( int , int& ); void totalPrice10( int , int& ); void totalPrice11( int , int& ); void totalPrice12( int , int& ); void totalPrice13(int , int& ); void totalPrice14(int , int& ); void totalPrice15(int , int& ); void totalPrice16(int , int& ); void receipt ( int& , int , int , int , int& , double& , double&); char code , numm2 , more; int quantity , quantity3 , option ; int optionForpet , num1 , quantity2 , quantity1 , totalPrice , totalQuantity , totalPrice111 = 0, totalPrice222 =0 , totalPrice333 =0 ; int accessories , more2 , more3 , foodMilk; double totalPricewithTax ; double totalPricewithFee; totalPrice = totalPrice111 + totalPrice222 + totalPrice333 ; totalQuantity =+ totalQuantity; totalPricewithTax = totalPrice * 0.06; totalPricewithFee = totalPrice + totalPricewithTax; int temp = 0; do { menu(); name(); read( option); system("cls"); switch(option) { case 1 : cout << " SPECIAL PETS FROM A VERY HIGH QUALITY BREEDER !\n\n"; cout << " ********************************************************\n "; cout << " We Give You The Best Quality of Pets\n"; cout << " 1. Persian Kitten ( Female )\t\t" << " RM 2000\n"; cout << " 2. Persian Kitten ( Male )\t\t" << " RM 1500\n" ; cout << " 3. Munchkin Kitten ( Female )\t\t" << " RM 2500\n"; cout << " 4. British Shorthair Kitten ( Female )\t" << " RM 3000\n"; cout << " 5. Return\n"; cin >> optionForpet; cout << " How many pet would you like to buy (maximum purchase = 3) : "; cin >> quantity; if ( quantity <=3 && quantity >=1) { switch (optionForpet) { case 1 : totalPrice1( quantity , totalPrice111 , temp); system("pause"); break; case 2 : totalPrice2( quantity , totalPrice111 , temp); system("pause"); break; case 3 : totalPrice3( quantity , totalPrice111 , temp); system("pause"); break; case 4 : totalPrice4( quantity , totalPrice111 , temp); system("pause"); break; case 5 : main(); system("pause"); break; default : cout << " Invalid input " << endl; } system("cls"); } else { cout << " Invalid. Try again! " << endl; cin >> quantity; return 0; } cout << " Do you want to purchase more ? (Y/y) = "; cin >> more; system("cls"); if( more == 'Y' || more == 'y' ) do { main(); cout << " total purchase for now = " << temp ; } while (option =! 5); else if ( more == 'N'|| more == 'n') { receipt( totalPrice , totalPrice111 , totalPrice222 , totalPrice333 , quantity , totalPricewithTax , totalPricewithFee ); return 0; } else { cout << " Thank You ! \n"; return 0; } case 2 : cout << " ACCESSORIES\n"; cout << " 1. Collars\t\t" << " (121) RM 30 (big)\t\t" << " (122) RM 25 (small)\n" ; cout << " 2. Leashes\t\t" << " (123) RM 50 (300CM)\t\t" << " (124) RM 40 (200CM)\n"; cout << " 3. Bowls\t\t" << " (125) RM 25 (big)\t\t" << " (126) RM 20 (small)\n" ; cout << " 4. Toys\t\t " << " (127) RM 20 (Plush)\t\t" << " (128) RM 30 (Rope)\n"; cout << " Enter the code to purchase = "; cin >> accessories; cout << " How many accessories would you like to purchase ? ( maximum purchases : 10 ) = \n"; cin >> quantity; if( quantity <= 10 && quantity >= 1) { switch(accessories); { case 121 : totalPrice5 ( quantity , totalPrice222 ); system("pause"); break; case 122 : totalPrice6 ( quantity , totalPrice222 ); system("pause"); break; case 123 : totalPrice7 ( quantity , totalPrice222 ); system("pause"); break; case 124 : totalPrice8 ( quantity , totalPrice222 ); system("pause"); break; case 125 : totalPrice9 ( quantity , totalPrice222 ); system("pause"); break; case 126 : totalPrice10 ( quantity , totalPrice222 ); system("pause"); break; case 127 : totalPrice11 ( quantity , totalPrice222 ); system("pause"); break; case 128 : totalPrice12 ( quantity , totalPrice222 ); system("pause"); break; default : cout << " Invalid code ! "; break; } } else { cout << " Invalid input . Try again !\n"; cin >> accessories; return 0; } cout << " Do you want to purchase more items ? (Y/y) ="; cin >> more2; system("cls"); if ( more2 == 'Y' || more2 == 'y') { main(); } else if ( more2 == 'N'|| more2 == 'n') { receipt(totalPrice , totalPrice111 , totalPrice222 , totalPrice333 , quantity , totalPricewithTax , totalPricewithFee); return 0; } else { cout << " Thank You !\n"; return 0; } case 3 : cout << " FOOD AND MILK ( AVAILABLE FOR CATS AND DOGS ONLY )\n"; cout << " __________________________________________________________________________________\n"; cout << " 1. Foods for Cats\t\t " << " (131) RM 50 (adult)\t\t " << " (132) RM 30 (kitten)\n"; cout << " 2. Foods for Dogs\t\t " << " (133) RM 55 (adult)\t\t" << " (134) RM 35 (puppy)\n"; cout << " Enter code = "; cin >> foodMilk; cout << " Quantity = " << endl; cin >> quantity; cout << " The total price is RM " <<endl; system("cls"); switch (foodMilk) { case 131 : totalPrice13 ( quantity , totalPrice333 ); system("pause"); break; case 132 : totalPrice14 ( quantity , totalPrice333 ); system("pause"); break; case 133 : totalPrice15 ( quantity , totalPrice333 ); system("pause"); break; case 134 : totalPrice16 ( quantity , totalPrice333 ); system("pause"); break; } cout << " Do you want purchase more ? (Y/y) "; cin >> more3; system("cls"); if ( more3 == 'Y' || more3 == 'y') main(); else if ( more3 == 'N'|| more3 == 'n') { receipt(totalPrice , totalPrice111 , totalPrice222 , totalPrice333 , quantity , totalPricewithTax , totalPricewithFee); return 0; } else { cout << " Thank You !\n"; return 0; } case 5 : cout << " Please visit our store again in the future ! \n "; return 0; break; } system("cls"); } while (option!= 5); return 0; } void menu() { cout << " WELCOME TO YO PETSHOP !\n" ; cout << "__________________________________________________\n\n"; cout << " Shop Our Products !\n"; cout << " 1. Pets \n"; cout << " 2. Accesories for pets \n" ; cout << " 3. Foods and Milk ( specially for cats and dogs only )\n" ; cout << " 5. Cancel\n" ; } void read( int& option ) { cout << " Select one option \n"; cin >> option ; } void name() { string name; cout << " Name of the buyer : " ; getline(cin , name) ; cout << " Hello , " << name << endl; } void totalPrice1 ( int quantity , int& totalPrice111 , int& temp) { totalPrice111 = 2000 * quantity; temp = totalPrice111; cout << " The total price is = " << totalPrice111 << endl; cout << " The total quantity is = " << quantity << endl; } void totalPrice2 ( int quantity , int& totalPrice111 , int& temp ) { totalPrice111 = 1500 * quantity; temp = totalPrice111; cout << " The total price is = " << totalPrice111 << endl; cout << " The total quantity is = " << quantity << endl; } void totalPrice3 ( int quantity , int& totalPrice111 , int& temp ) { totalPrice111 = 2500 * quantity; temp = totalPrice111; cout << " The total price is = " << totalPrice111 << endl; cout << " The total quantity is = " << quantity << endl; } void totalPrice4 ( int quantity , int& totalPrice111 , int& temp) { totalPrice111 = 3000 * quantity; temp = totalPrice111; cout << " The total price is = " << totalPrice111 << endl; cout << " The total quantity is = " << quantity << endl; } void totalPrice5 ( int quantity , int& totalPrice222 ) { totalPrice222 = 30 * quantity ; cout << " The total price is = " << totalPrice222 << endl; cout << " The total quantity is = " << quantity << endl; } void totalPrice6 ( int quantity , int& totalPrice222 ) { totalPrice222 = quantity * 25; cout << " The total price is = " << totalPrice222 << endl; cout << " The total quantity is = " << quantity << endl; } void totalPrice7 ( int quantity , int& totalPrice222 ) { totalPrice222 = quantity * 50; cout << " The total price is = " << totalPrice222 << endl; cout << " The total quantity is = " << quantity << endl; } void totalPrice8 ( int quantity , int& totalPrice222 ) { totalPrice222 = quantity * 40; cout << " The total price is = " << totalPrice222 << endl; cout << " The total quantity is = " << quantity << endl; } void totalPrice9 ( int quantity , int& totalPrice222 ) { totalPrice222 = quantity * 25; cout << " The total price is = " << totalPrice222 << endl; cout << " The total quantity is = " << quantity << endl; } void totalPrice10 ( int quantity , int& totalPrice222 ) { totalPrice222 = quantity * 20; cout << " The total price is = " << totalPrice222 << endl; cout << " The total quantity is = " << quantity << endl; } void totalPrice11 ( int quantity , int& totalPrice222 ) { totalPrice222 = quantity * 20; cout << " The total price is = " << totalPrice222 << endl; cout << " The total quantity is = " << quantity << endl; } void totalPrice12 ( int quantity , int& totalPrice222 ) { totalPrice222 = quantity * 30; cout << " The total price is = " << totalPrice222 << endl; cout << " The total quantity is = " << quantity << endl; } void totalPrice13 ( int quantity , int& totalPrice333 ) { totalPrice333 = quantity * 50; cout << " The total price is = " << totalPrice333 << endl; cout << " The total quantity is = " << quantity << endl; } void totalPrice14 ( int quantity , int& totalPrice333 ) { totalPrice333 = quantity * 30; cout << " The total price is = " << totalPrice333 << endl; cout << " The total quantity is = " << quantity << endl; } void totalPrice15 ( int quantity , int& totalPrice333 ) { totalPrice333 = quantity * 55; cout << " The total price is = " << totalPrice333 << endl; cout << " The total quantity is = " << quantity << endl; } void totalPrice16 ( int quantity , int& totalPrice333 ) { totalPrice333 = quantity * 35; cout << " The total price is = " << totalPrice333 << endl; cout << " The total quantity is = " << quantity << endl; } void receipt( int& totalPrice , int totalPrice111 , int totalPrice222 , int totalPrice333 , int& quantity , double& totalPricewithTax , double& totalPricewithFee) { string name; totalPrice = totalPrice111 + totalPrice222 + totalPrice333 ; totalPricewithTax = totalPrice * 0.06; totalPricewithFee = totalPrice + totalPricewithTax; cout << " YO PETSHOP \n" ; cout << "___________________________________\n"; cout << " Buyer's name = " << name << endl; cout << " Total Purchase = " << totalPrice << endl; cout << " Total Quantity = " << quantity << endl; cout << " Tax = " << totalPricewithTax << endl; cout << " Fee = " << totalPricewithFee << endl << endl; cout << " THANK YOU FOR YOUR PURCHASE ! "; }
Rick York
Этот раздел вопросов и ответов предназначен для того, чтобы задать конкретный вопрос, на который мы постараемся дать конкретные ответы. Размещение кучи кода и обращение за помощью с ним не входит в намерения данного раздела. Вы, вероятно, не получите очень много помощи с такого рода вопросом. Я знаю, что мне неинтересно читать кучу кода и пытаться разобраться в нем, и я не могу представить, что кто-то другой тоже будет это делать.
Richard MacCutchan
Этот код слишком сложен для такой простой задачи, и, вероятно, его невозможно отладить.
Richard MacCutchan
Извините, но это действительно не очень хороший способ написания вашей программы; все эти totalPriceX
функции будут вызывать проблемы. Я предлагаю вам найти хорошую книгу по C/C++.