gpt4 book ai didi

c++ - 为什么 while 循环会跳过 char?

转载 作者:行者123 更新时间:2023-11-28 03:22:39 25 4
gpt4 key购买 nike

<分区>

所以我试图设置一个 while 循环来继续询问 (y/n),但是当我按“y”并输入时,为什么会跳过“char itemtitle”并直接进入“double itemprice”?我真的是 c++ 的新手,请帮忙,我会很感激

#include <cstdlib>
#include <iostream>
#include <sstream>

using namespace std;

#define tax 9.99
#define shipping ("Free")

void printmessage ()
{
cout << "*Thanks for your business! We'll ship out your item as soon as possible*\n"
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n";
}

int main(int argc, char** argv)
{

cout << "Write an invoice program and print it to the console.\n";
cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n;

cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"
"Welcome to my Pc Store.\n"
"'Where Technology is served right'\n"
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"<< endl;

char name [256];
cout << "Enter your full name: ";
cin.getline (name, 256);

char organization [256];
cout << "What's your organization?: ";
cin.getline (organization, 256);

char quit = 'y';
do {
char itemtitle [256];
cout << "Enter name of Laptop you'd like to order: ";
cin.getline (itemtitle, 256);

double itemprice;
cout << "Enter price of item: $";
cin >> itemprice;

int quantity;
quantity = 1;
cout << "How many items?: ";
cin >> quantity;

if (quantity == 1) {
cout << "1 item(s)\n";
} else {
cout << quantity << " item(s)\n";
}

cout << "Tax: $" << tax;

double subtotal;
subtotal = quantity * itemprice + tax;
cout << "\nSub Total: $" << subtotal;

cout << "\n";
cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n"
"Validation:\n\n";

cout << "Item(s):\t\t\t\t\t" << "Amount:\n";
cout << itemtitle << "\t\t\t\t\t$" << quantity * itemprice + tax; ;
cout << "\n" << quantity << " * $" << itemprice << " + $" << tax;

cout << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n";
cout << "Payment (Credit/Debit only)!\n\n";

double cardnum;
cout << "Card Numbers: ";
cin >> cardnum;

int ssn;
cout << "SSN: ";
cin >> ssn;

cout << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"
"Invoice Details:\n\n";

time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
cout << "Date&Time: " << ("Current local time and date: %s", asctime (timeinfo));

cout << name;
cout << "\n" << organization;
cout << "\n" << "("<< quantity << ")" << " " << itemtitle;

cout << "\n\t\t\t" << "Total: $" << quantity * itemprice;
cout << "\n\t\t\t" << "Tax: $" << tax;
cout << "\n\t\t\t" << "Shipping: " << shipping;
cout << "\n\n\t\t\t" << "Balance Due: $" << quantity * itemprice + tax;

cout << "\n\t\t\t" << "Payment: " << "Paid" ;

cout << "\n\n\nDo you want to continue shopping? (y/n): ";
cin >> quit ;

cout << "\n\n";

} while (quit != 'n');

cout << "\n\n\n";
printmessage ();

return 0;
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com