-2
用戶應輸入名稱,然後輸入成績。當用戶擊中-1時,可以不再爲該個人存儲更多等級。當用戶鍵入X時,他/她輸入總數,然後輸入-1表示不能再存儲更多等級。我不明白爲什麼我的for循環以奇怪的方式輸出。 names數組存儲應該轉到numbers數組的int值。將數值存儲在數組中
例如,輸入應該是這樣的:
Jane 3 4 -1
Lane 4 5 -1
X 10 10 -1
輸出應該是這樣的:
Jane 3 4
Jane had a 7/20
Lane 4 5
Lane had a 9/20
這是迄今爲止我的工作:
#include <iostream>
#include <cstring>
#include <string>
using namespace std;
int main()
{
string name = " ";
string names[20];
int numbers[20];
int i = 0, j=0, number;
do
{
cin >> name;
names[i]=name;
i++;
j=0;
if(number!=-1)
{
cin>> number;
numbers[j]=number;
j++;
}
}while(name!="X");
for(int x = 0; x <= i; x++)
{
for(int y = 0; y <= j; y++)
{
cout << names[x];
}
}
}
什麼是_your_理論? –
你不用'y'就可以遍歷'y'。爲什麼? –
如果您使用C++,那麼爲什麼不使用STL? –