Sum of n numbers( n is entered by user).
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
int x = 1, n, number, total;
total = 0;
cout << "Enter how many numbers you want to add: " << endl;
cin >> n;
for(x; x<=n; x++){ //Important
cout << "Enter " << x << " number: " << endl;
cin >> number;
total = total + number;
}
cout << total << endl;
return 0;
}
Comments
Post a Comment