Write a C++ program that asks the user to enter a positive integer to be held by
ID: 3545847 • Letter: W
Question
Write a C++ program that asks the user to enter a positive integer to be held by a variable call n. The program should then make use of a loop to ask the user for an integer value over and over again. Each time the loop iterates the program should add the integer value to the tally so that the total sum of the input integers can be output. The loop should iterate n times. That is, the user wil tell the program how many integers that they would like to enter (held by n), and then the loop will iterate n times to obatin the the n input integers and calculate the sum of all those integers. The program will then output the sum.
write a program for me using C++ ??
Explanation / Answer
#include <iostream>
#include <cmath>
using namespace std;
int main ()
{
int n = 0;
int z = 0;
int sum = 0;
cout << "Enter the N value: " << endl;
cin >> n;
for(int i =1; i <=n; i++)
{
cout << "enter the [" << i << "] integer: " ;
cin >> z;
sum = sum + z;
}
cout << "The total is: " << sum << endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.