Solution to Write a program that uses for loops to perform the following steps: Prompt the user … - Sikademy
Author Image

Archangel Macsika

Write a program that uses for loops to perform the following steps: Prompt the user to input two integers: firstNum and secondNum (firstNum must be less than secondNum). Output all odd numbers between firstNum and secondNum. Output the sum of all even numbers between firstNum and secondNum. Output the numbers and their squares between 1 and 10. Separate the numbers using any amount of spaces. Output the sum of the square of the odd numbers between firstNum and secondNum. Output all uppercase letters.

The Answer to the Question
is below this banner.

Can't find a solution anywhere?

NEED A FAST ANSWER TO ANY QUESTION OR ASSIGNMENT?

Get the Answers Now!

You will get a detailed answer to your question or assignment in the shortest time possible.

Here's the Solution to this Question


#include <iostream> using namespace std; int main() {     //a. Prompt the user to input two integers: firstNum and secondNum     //(firstNum must be less than secondNum).     cout << "a. Prompt the user to input two integers. First must be less than second\n";     double firstNum = 2;     double secondNum = 1;     while (firstNum > secondNum)     {        cout << "enter first number: \n";        cin >> firstNum;        cout << "enter second number (must be more than first number): \n";        cin >> secondNum;        if (firstNum > secondNum)             cout << "first number must be less than second number. Try again. \n";     }     cout << "\n";     //b. Output all odd numbers between firstNum and secondNum.     cout << "b. Output all odd numbers between firstNum and secondNum.\n";     int number = firstNum;     while (number <= secondNum)     {         if (number % 2)             cout << number++ << "\n";         else         {             number++;             continue;         }     }     cout<<"\n";     //c. Output the sum of all even numbers between firstNum and secondNum.     cout << "c. Output the sum of all even numbers between firstNum and secondNum.\n";     number = firstNum;     int sum = 0;     while (number <= secondNum)     {         if (!(number % 2))             sum += number++;         else         {             number++;             continue;         }     }     cout << "sum = " << sum << "\n\n";     //d. Output the numbers and their squares between 1 and 10.     cout << "d.Output the numbers and their squares between 1 and 10.\n";     number = 1;     while (number <= 10)     {         cout << number << " -> " << number << "^2" << " = " << number * number << '\n';         number++;     }     cout << "\n";     //e. Output the sum of the square of the odd numbers between firstNum and secondNum.     cout << "Output the sum of the square of the odd numbers between firstNum and secondNum\n";     number = firstNum;     sum = 0;     while (number <= secondNum)     {         if (number % 2)         {             sum += (number * number);             number++;         }         else         {             number++;             continue;         }     }     cout << "sum: " << sum << "\n\n";     //f. Output all uppercase letters.     cout << "Output all uppercase letters.\n";     int c = 65;     while (c < 91)         cout << char(c++) << ", ";     cout << "\n"; }

Related Answers

Was this answer helpful?

Join our Community to stay in the know

Get updates for similar and other helpful Answers

Question ID: mtid-3-stid-44-sqid-1078-qpid-74