example of for-loops
This commit is contained in:
parent
9248b5b621
commit
f79359da32
|
@ -0,0 +1,21 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
|
||||
double sum = 0;
|
||||
int numThings = 0;
|
||||
|
||||
cout << "Enter the number of things to be summed: ";
|
||||
cin >> numThings;
|
||||
|
||||
for(int i = 0; i < numThings; i++){
|
||||
double temp = 0;
|
||||
cout << "Enter a number: ";
|
||||
cin >> temp;
|
||||
sum = sum + temp;
|
||||
}
|
||||
|
||||
cout << "Here's your final sum: " << sum << endl;
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue