#include <iostream>
#include <cmath>
using namespace std;
int main()
{
string num[21];
int amount_num;
cout<< "How many numbers do you want? (max 20)\n";
cin>> amount_num;
if (amount_num<= 0 || amount_num >= 22)
{
cout << "Invalid size. Ending.\n";
}
for (int counter =0; counter < amount_num; counter++)
{
cout<< "Enter vaule "<< counter<< ":"<< endl;
cin>> num[counter];
}
for(int t= 0; t< amount_num; t++)
{
int total;
int average;
total = total + num[t];
average= total/ t;
cout<< "Average: "<< average<< endl;
}
for(int x=0; x< amount_num; x++)
{
cout<< "You entered:"<< endl;
cout<< num[x]<< endl;
}
}
當我嘗試添加總加上num [t]時,錯誤不斷彈出。 它聲明:錯誤沒有操作符+總數+ num [t]。編寫一個程序,查找多個浮點數的平均值。允許用戶指定將輸入多少個值。限制數量爲20
爲什麼你有'string'數組? –
不能將int和字符串相加 – orangegoat
我將字符串更改爲float。我也將變量總數改爲浮動。我是如何得到平均水平的問題。它給我三個不同的答案 – user2647244