Answer to Question #183008 in C++ for Vincenzo Santoro

Question #183008

Write a program that uses while loops to perform the following steps:

  1. Prompt the user to input two integers: firstNum and secondNum
  • (firstNum must be less than secondNum).
  1. Output all odd numbers between firstNum and secondNum.
  • Separate each number with a space
  1. Output the sum of all even numbers between firstNum and secondNum.
  2. Output the numbers and their squares between 1 and 10.
  3. Output the sum of the square of the odd numbers between firstNum and secondNum.
  4. Output all uppercase letters.
  • Separate each letter with a space
1
Expert's answer
2021-04-25T15:19:04-0400
#include <iostream>

using namespace std;

int main()
{
    int firstNum = 0;
    int secondNum = 0;

    cout << "Enter first number: ";
    cin >> firstNum;

    cout << "Enter second number: ";
    cin >> secondNum;

    if (firstNum >= secondNum) {
        cout << "First number must be less then second number" << endl;
        return 0;
    }

    cout << "Odd numbers: ";
    int i = firstNum;
    while (i <= secondNum) {
        if (i % 2 == 1)
            cout << i << " ";
        i++;
    }

    cout << endl << "Even numbers: ";
    i = firstNum;
    while (i <= secondNum) {
        if (i % 2 == 0)
            cout << i << " ";
        i++;
    }

    cout << endl << "Numbers and squares: ";
    i = 1;
    while (i <= 10) {
        cout << i << ":" << i * i << " ";
        i++;
    }

    int sum = 0;
    i = firstNum;
    while (i <= secondNum) {
        if (i % 2 == 1)
            sum += i * i;
        i++;
    }
    cout << endl << "Sum of squares: " << sum;

    cout << endl << "Uppercase letters: ";
    char c = 'A';
    while (c <= 'Z') {
        cout << c << " ";
        c++;
    }
    cout << endl;

    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