Answer to Question #256192 in C++ for Sarang

Question #256192
  1. Ask the user to input three values (1) Start, (2) Step and (3) Stop
  2. Use any looping statement you learned and output the series of numbers based on the start, step and stop values, see sample output below.

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





1
Expert's answer
2021-10-25T17:56:05-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS