How do I write a C++ program with loop statement (while, for, or do…while) to prompt users to enter 10 integers and calculate the total of these integers?
Answers
Answered by
4
The given problem is solved using language - C++.
#include <iostream>
using namespace std;
int main() {
cout<<"Enter ten integers...\n\n";
int sum=0,i,a;
for(i=0;i<10;i++){
cout<<"Enter: ";
cin>>a;
sum+=a;
}
cout<<"\nThe sum of the ten numbers you entered is: "<<sum;
return 0;
}
- Initialise sum = 0.
- Repeat I = 0 to 9.
- Accept the number from the user.
- Add the number to sum.
- I = I + 1.
- Display the value of sum.
Enter ten integers...
Enter: 1
Enter: 2
Enter: 3
Enter: 4
Enter: 5
Enter: 6
Enter: 7
Enter: 8
Enter: 9
Enter: 10
The sum of the ten numbers you entered is: 55
Attachments:
Similar questions