Input Output
Start: 0 0, 2, 4, 6, 8
Step: 2 count: 4
Stop: 8 sum: 20
Start: 2 2, 6, 10
Step: 4 count: 3
Stop: 12 sum: 18
Start: 1 1, 2, 3, 4, 5
Step: 1 count: 5
Stop: 5 sum: 15
This should be what I'll see when I run the program like this below:
SCREEN LAYOUT / DESIGN
START: 0
STEP: 2
STOP: 10
SSS: 0 2 4 6 8 10
COUNT: 6
SUM: 30
Try Another [Y/N]:Y
#include <iostream>
int main()
{
int start;
int stop;
int step;
int count;
int sum;
for (char choise ='Y'; choise == 'Y';)
{
std::cout << "START:";
std::cin >> start;
std::cout << "STEP:";
std::cin >> step;
std::cout << "STOP:";
std::cin >> stop;
count = 0;
sum = 0;
std::cout << "SSS:";
for (int i = start; i <= stop; i += step)
{
std::cout << i<<" ";
sum += i;
count++;
}
std::cout << "\n";
std::cout << "COUNT:" << count << "\n";
std::cout << "SUM:" << sum << "\n";
std::cout << "\n";
std::cout << "Try Another [Y/N]:";
std::cin >> choise;
}
return 0;
}
Comments
Leave a comment