Write a code that ask the user for the number n of decimal to average.
Then n times the code the user to enter all numbers that you save or accumulate each time.
Finaly print to the console the average of the n values the user entered using the format:
cout << \" The average of the \" << n << \" number you entered is: \" << averagedValue <<endl;
Solution
Answer
#include <iostream>
using namespace std;
int main()
{
int n,averagedValue,num,total=0;
cout<<\"\ Enter count of numbers : \"; //input count of numbers
cin>>n;
for(int i=1;i<=n;i++)
{
cout<<\"\ Enter number \"<<i<<\" : \"; //input number
cin>>num;
total=total+num; //adds to total
}
averagedValue=total/n; //calculates average
cout<<\"\ \ The average of the \"<<n<<\" number you entered is: \"<<averagedValue;
return 0;
}
.