## C++ Programming Assignment Help - Solution on Sum and the Average of The Numbers

• 20th Oct, 2022
• 00:55 AM

C++ Programming Assignment Help - Solution on Sum and the Average of The Numbers

#include
#include
using namespace std;

int sumOfArray(int arr[5])
{
int sum =0;
for(int i=0;i<5;i++)
{
sum = sum+arr[i];
}
return sum;
}

float avgOfArray(int arr[5])
{
int sum =0;
float avg;
for(int i=0;i<5;i++)
{
sum = sum+arr[i];
}
avg = (float)sum/5;
return avg;
}
int main()
{
int arr[5];
int sum ;
float avg;
int userChoice;
cout<<"Enter 5 numbers "<     for(int i=0;i<5;i++)
{
cin>>arr[i];
}
cout<<"Press 1 calculate the average of the numbers entered"<      cout<<"Press 2 calculate the sum of the numbers entered"<      cout<<"Press 3 calculate both the sum and the average of the numbers entered"<      cin>>userChoice;
switch(userChoice)
{
case 1:
{
avg = avgOfArray(arr);
cout<<"The average of the numbers entered is: "<           break;
}
case 2:
{
sum = sumOfArray(arr);
cout<<"The sum of the numbers entered is: "<           break;
}
case 3:
{
sum = sumOfArray(arr);
avg = avgOfArray(arr);
cout<<"The average of the numbers entered is: "<           break;
}
default:
{
cout<<"Wrong Input by User"<         }
}
return 0;
}