我已经制作了这个销售点程序,其中硬编码了三个项目,变量a_book
,a_bat
和a_hat
在我输入数量时不会更新。为什么?
#include <iostream>
#include <stdio.h>
#include <unistd.h>
#include <cstdlib>
using namespace std;
int main(void)
{
int selectionMain;
int selection;
int a_book;
int a_bat;
int a_hat;
cout << "\n\nHello, welcome to mIke's Convenience! How may I help you?" << endl;
printf("\n\n\n");
cout << "1. add products\n\n" << endl;
cout << "2. remove products\n\n" << endl;
cout << "3. procede to receipt\n\n\n" << endl;
cout << "4. exit\n\n\n" << endl;
printf("Please make a selection: ");
scanf(" %d", &selectionMain);
printf("\n\n\n");
if(selectionMain == 1){
cout << "You have selected 1.\n\n\n" << endl;
cout << "1. book - $5.00 ea\n\n" << endl;
cout << "2. baseball bat - $11.00 ea\n\n" << endl;
cout << "3. hat - $7.00 ea\n\n\n" << endl;
printf("please select a product to add by typing a number (1, 2, 3): ");
scanf(" %d", &selection);
if(selectionMain == 1){
printf("select desired quantity of books to add: ");
scanf(" %d", &a_book);
}else if(selectionMain == 2){
printf("select desired quantity of baseball bats to add: ");
scanf(" %d", &a_bat);
}else{
printf("select desired quantity of hats to add: ");
scanf(" %d", &a_hat);
}
return main();
}else if(selectionMain == 2){
cout << "You have selected 2.\n\n\n" << endl;
cout << "1. book - $5.00 ea\n\n" << endl;
cout << "2. baseball bat - $11.00 ea\n\n" << endl;
cout << "3. hat - $7.00 ea\n\n\n" << endl;
printf("please select a product to remove by typing a number (1, 2, 3): ");
scanf(" %d", &selectionMain);
return main();
}else if(selectionMain == 3){
cout << "You have selected 3.\n\n\n" << endl;
cout << "-------your receipt-------\n\n\n" << endl;
printf("book(s) x %d!\n", a_book);
printf("baseball bat(s) x %d!\n", a_bat);
printf("hat(s) x %d!\n\n", a_hat);
cout << "-----Thank you for shopping at mIke's Convenience. Please play responsibly?-----\n\n\n" << endl;
printf("press any letter key and then 'Enter' to return to main screen ");
scanf(" %d", &selectionMain);
return main();
}else{
void exit();
}
return 0;
}