C++ Programming Question: Download Questions PDF
Write a program that ask for user input from 5 to 9 then calculate the average
![C++ Programming Interview Answer C++ Programming Interview Question](https://globalguideline.com/public/images/interview/24.png)
Answer:
#include "iostream.h"
int main() {
int MAX = 4;
int total = 0;
int average;
int numb;
for (int i=0; i<MAX; i++) {
cout <<
"Please enter your input between 5 and 9: ";
cin >> numb;
while ( numb<5 || numb>9) {
cout << "Invalid input, please re-enter: ";
cin >> numb;
}
total = total + numb;
}
average = total/MAX;
cout << "The average number is: "
<< average << "n";
return 0;
}
int main() {
int MAX = 4;
int total = 0;
int average;
int numb;
for (int i=0; i<MAX; i++) {
cout <<
"Please enter your input between 5 and 9: ";
cin >> numb;
while ( numb<5 || numb>9) {
cout << "Invalid input, please re-enter: ";
cin >> numb;
}
total = total + numb;
}
average = total/MAX;
cout << "The average number is: "
<< average << "n";
return 0;
}
Download C++ Programming Interview Questions And Answers
PDF
Previous Question | Next Question |
What do you mean by inline function? | Write a short code using C++ to print out all odd number from 1 to 100 using a for loop |