Code:
#include <iostream>
using namespace std;
int main()
{
int n, i;
float num[100], sum=0.0, average;
cout << "Enter the number of subjects: ";
cin >> n;
while (n > 6 || n <= 0)
{
cout << "Error..entered number for subjects count is
exceeded: ";
cin >> n;
}
for(i = 0; i < n; ++i)
{
cout << i + 1 << ". Enter subject score: ";
cin >> num[i];
sum += num[i];
}
average = sum / n;
cout << "Total = "<<sum;
cout << "Average = " << average;
return 0;
}
Output:
Enter the number of subjects: 4
Enter subject score: 35
Enter subject score: 85
Enter subject score: 96
Enter subject score: 48
Total = 264
Average = 66
Get Answers For Free
Most questions answered within 1 hours.