example of for-loops

This commit is contained in:
left_adjoint 2024-01-19 13:43:25 -08:00
parent 9248b5b621
commit f79359da32
1 changed files with 21 additions and 0 deletions

21
forInput.cpp Normal file
View File

@ -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;
}