Infinite Sums
Make a program that takes an input and adds it to a sum. Make the process of taking an input and adding it to a sum repeat itself until the user inputs 0.
Example
4
6
9
14
0
4
10
19
33
Answer
#include <iostream>
int main()
{
std::cout << "Input the numbers you want to add together (seperated by enter)\n"
<< "Enter 0 when you are done.\n";
float sum = 0;
float input;
do
{
std::cin >> input;
sum += input;
std::cout <<"=" << sum << "\n+";
} while (input != 0);
}
The format of the second
std::coutline makes it so that every number you add is has a+symbol in front of it, and every number the program outputs has a=symbol in front of it.