For the midterm you will use Visual Studio software on your XenDesktop to write
ID: 3795521 • Letter: F
Question
For the midterm you will use Visual Studio software on your XenDesktop to write a C++ Program called Average which asks the user to enter integers, and continues asking for input until the user enters “9999.” You may use your textbooks and notes to solve the problem. There is not time restriction for completing your exam. This exam counts for 50% of your total midterm grade.
When the user has entered “9999,” the program displays the number entries, and the average.
In other words, if the user enters 20, 40, 60, and 80, and then 9999, the output would look like this:
Explanation / Answer
#include <iostream>
int main()
{
int avg=0; // initial value of avg=0
int sum=0; // sum is initialize as 0
int value[100]; // Taking array of 100 elements
int i=0; // define i value as 0
do
{
std::cin>>value[i]; // Taking input values
i=i+1;
}while(value[i-1]!=9999); // Check the input termination condition when value = 9999
std::cout<<"Input Numbers are: ";
for(int j=0;j<i-1;j++)
{
sum=sum+value[j]; // Summation of the All values
std::cout<<value[j]<<" "; // Printing all values
}
avg=sum/(i-1); // Taking average
std::cout<<" Average is : "<<avg<<" "; // display average value
}
Input Values:
20
40
60
80
9999
55
56
5
45
Output