#include <iostream>
using namespace std;
int main()
{
string input; //User input
char a; //Individual characters
int score(0); //Final score
int numa(0); //Number of a
int numg(0); //Number of g
int numm(0); //Number of m
int numf(0); //Number of f
int numk(0); //Number of k
int numj(0); //Number of j
cout << "Enter Text: "; //Requesting and storing user input
cin >> input;
cout << endl;
a = input[0];
cout << a;
if(a != '!' || a != '.')
{
int num(0);
while(num<=input.length())
{
a = input[num];
switch(a)
{
case 'a':
case 'A':
score += 1;
numa++;
break;
case 'g':
case 'G':
score += 2;
numg++;
break;
case 'm':
case 'M':
score += 3;
numm++;
break;
case 'f':
case 'F':
score += 4;
numf++;
break;
case 'k':
case 'K':
score += 5;
numk++;
break;
case 'j':
case 'J':
score += 8;
numj++;
break;
default:
break;
}
num++;
}
}
cout << "Number of a's (worth 1 point each): " << numa << endl;
cout << "Number of g's (worth 2 point each): " << numg << endl;
cout << "Number of m's (worth 3 point each): " << numm << endl;
cout << "Number of f's (worth 4 point each): " << numf << endl;
cout << "Number of k's (worth 5 point each): " << numk << endl;
cout << "Number of j's (worth 8 point each): " << numj << endl;
cout << endl;
cout << "Total score: " << score;
}
該程序需要用戶輸入並根據其中包含的內容給出分數。字母a給1分,g給2,m給3,f給4,k給5,j給8。要麼 」。」。所以,雖然aaa!和aaa。給出3分,aaa!aa和aaa.aa也應該只給3分,因爲在「!」後面的所有內容和「。」被忽視。如果字符串不以「!」結尾,它也不應該運行。或「。」,aaaa!和aaaa。兩者都返回4分,而aaaa不返回任何結果。麻煩的是,如果在switch語句中沒有定義空格或字母t,程序就不會運行。最終目標是爲了這個聲明,「她做了一個熟悉的嘗試恰到好處。」返回一個分數的28C++ Space while while循環
我認爲你需要在你最喜歡的書中閱讀更多關於什麼是用空白符做的事情。 – molbdnilo
嗨molbdnilo,我還是很新的C++。 Does >>與普通人物不同的處理空白? – INeedHelp101
確實如此。無論你從中學到什麼材料都應該教這個,但如果它沒有好書的列表[這裏](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-和列表)。 – molbdnilo