-2
我需要幫助將值與某些字符串相關聯,以便在用戶輸入它們之後計算平均值。 所以我嘗試使用string :: find,因爲值是順序的; 我結束了這段代碼:我需要幫助將valus與字符串相關聯來計算平均值
string str1, str2, str3, str4, str5;
string::size_type position;
float media;
str1 = "NSMBE";
cout << str1.find("N") +1 << endl;
cout << str1.find("M") + 1 << endl;
cout << str1.find("M") + 1 << endl;
cout << str1.find("B") + 1 << endl;
cout << str1.find("E") + 1 << endl;
但是現在我如何從這裏去獲取用戶輸入,使相等值的字符串? 示例:用戶輸入等級1的N和等級2的M;所以N = 1和M = 2,所以我應該得到的平均值是(1 + 2)/ 2。 ..
我敢肯定,這是非常簡單和容易的事情,但我到處搜索,以找到答案,而不是。
一個很棒的地方開始將是[cplusplus教程](http://www.cplusplus.com/doc/tutorial/)。 –