如何将输入的字符串存储到数组中?
我希望有人能给我一些关于如何在数组中存储输入的提示..
我想将项目存储在数组中。
#include <iostream>
using namespace std;
int main() {
cout << "MANG JUAN'S 10-DAHAN\n\n";
cout << "A - BALOT = 25.00\tD - KETCHUP = 50.00\tG - VINEGAR = 25.00\n";
cout << "B - CANTON = 20.00\tE - MAGGI = 15.00\tH - OIL = 70.00\n";
cout << "C - NIDO = 100.00\tF - ALASKA = 60.00\tI - COKE = 10.00\n";
cout << "\nWOULD YOU LIKE TO PURCHASE? Y/N\n\n";
int quantity;
char item, addAnother, choice;
double price, total, grandTotal;
cin >> choice;
if (choice == 'n' || choice == 'N') {
cout << "\n\nThank you.\n\n";
} else if (choice == 'y' || choice == 'Y') {
string numPref;
int i = 1;
while ( i <= 10 ) {
switch(i) {
case 1: numPref = "st";
break;
case 2: numPref = "nd";
break;
case 3: numPref = "rd";
break;
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10: numPref = "th";
break;
default: cout << "\n\nTHE SYSTEM EXCEEDED ITS LIMIT\n\n";
}
cout << "\n\nPLEASE ENTER " << i << numPref << " ITEM:\t";
cin >> item;
if( !cin ) {
cout << "ENTER A - H ONLY..";
} else {
cout << "HOW MANY?\t";
cin >> quantity;
switch(item) {
case 'a':
case 'A':
case 'g':
case 'G':
price = 25.00;
break;
case 'b':
case 'B':
price = 20.00;
break;
case 'c':
case 'C':
price = 100.00;
break;
case 'd':
case 'D':
price = 50.00;
break;
case 'e':
case 'E':
price = 15.00;
break;
case 'f':
case 'F':
price = 60.00;
break;
case 'h':
case 'H':
price = 70.00;
break;
case 'i':
case 'I':
price = 10.00;
break;
}
cout << "PRICE PER ITEM\t" << price << endl;
total = quantity * price;
cout << "TOTAL\t\t" << total << "\n\n";
grandTotal += total;
cout << "ADD ANOTHER ITEM? Y/N" << endl;
cin >> addAnother;
if ( addAnother == 'n' || addAnother == 'N' ) {
cout << "\n\nPLEASE PAY: " << grandTotal;
cout << "\n\n";
break;
} else if ( addAnother == 'y' || addAnother == 'Y' ) {
cout << i++;
} else { cout << "INVALID INPUT.."; break;}
}
}
} else {
cout << "INVALID INPUT..\n\n";
}
system("PAUSE");
return 0;
}
我正在用C ++复习自己,不幸的是我忘记了如何存储数组..