所以我制作了一个非常简单的程序,该程序允许用户选择一些项目并将总计添加到购物篮中并显示给用户。
但是在程序中我使用(£)符号的任何地方,由于某种原因,它会显示为u,这是为什么会发生这种情况的原因。
在整个程序中尝试使用(£)的ive仍然得到相同的结果
#include <iostream>
#include <limits>
using namespace std;
int main() {
int choice;
int itemsWant;
int itemsNum = 0;
double basket = 0;
cout << "Welcome to the small store please browse our shopping list below."
<< endl;
cout << " 1 - Bread = £1" << endl;
cout << " 2 - Eggs = £1.25" << endl;
cout << " 3 - Milk = £0.75" << endl;
cout << " 4 - Water = £0.50" << endl;
cout << " 5 - Juice = £1" << endl;
cout << " 6 - Fizzy Pop = £1.50" << endl;
cout << " 7 - Crisps = £1" << endl;
cout << " 8 - Sandwich = £2" << endl;
cout << " 9 - Pizza = £2" << endl;
cout << " 10 - Cake = £3" << endl;
cout << "How many items would you like to purchase from the list? ";
while(!(cin >> itemsWant)) {
cout << "INVALID CHOICE: enter a number: ";
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
do {
cout << " Please make your choice(1-10): ";
while(!(cin >> choice)) {
cout << "INVALID CHOICE: enter a item from the list using the "
"corresponding number: ";
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
if(choice >= 1 && choice <= 10) {
switch(choice) {
case 1:
cout << "Thanks Bread has been added to your basket" << endl;
itemsNum++;
basket += 1;
break;
case 2:
cout << "Thanks Eggs has been added to your basket" << endl;
itemsNum++;
basket += 1.25;
break;
case 3:
cout << "Thanks Milk has been added to your basket" << endl;
itemsNum++;
basket += 0.75;
break;
case 4:
cout << "Thanks Water has been added to your basket" << endl;
itemsNum++;
basket += 0.50;
break;
case 5:
cout << "Thanks Juice has been added to your basket" << endl;
itemsNum++;
basket += 1;
break;
case 6:
cout << "Thanks Fizzy Pop has been added to your basket" << endl;
itemsNum++;
basket += 1;
break;
case 7:
cout << "Thanks Crisps has been added to your basket" << endl;
itemsNum++;
basket += 1;
break;
case 8:
cout << "Thanks Sandwich has been added to your basket" << endl;
itemsNum++;
basket += 2;
break;
case 9:
cout << "Thanks Pizza has been added to your basket" << endl;
itemsNum++;
basket += 2;
break;
case 10:
cout << "Thanks Cake has been added to your basket" << endl;
itemsNum++;
basket += 3;
break;
}
}
} while(itemsNum < itemsWant);
if(choice > 10) {
cout << "Invalid Choice! " << endl;
}
cout << "\n\nYou Purchased " << itemsNum << " Items." << endl;
cout << "The Final Total is: £" << basket << endl;
;
cout << "Thanks for shopping at the small store please come again.";
return 0;
}
我希望输出为£,但是我却得到了你