Answer to Question #269968 in C++ for DANISH

Question #269968

LOOPS

Write a program that uses while 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.
  • Output the sum of the square of the odd numbers between firstNum

and secondNum.

  • Output all uppercase letters.




















1
Expert's answer
2021-11-22T09:34:27-0500
#include <iostream>
using namespace std;




int main()
{
    
    
    double firstNum = 2;
    double secondNum = 1;
    while (firstNum > secondNum)
    {
       cout << "Enter first number: ";
       cin >> firstNum;
       cout << "Enter second number (must be more than first number): ";
       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 << "All odd numbers between first number and second number:\n";
    int number = firstNum;
    int sum = 0;
	while (number <= secondNum)
    {
        if (number % 2!=0){
            cout << number<< "\n";
		}else{
			sum+=number;
		}
		
		number++;
    }
    //c. Output the sum of all even numbers between firstNum and secondNum.
    cout << "\nThe sum of all even numbers between first number and second number: "<<sum<<"\n";
    //d. Output the numbers and their squares between 1 and 10.
    cout << "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.
    number = firstNum;
    sum = 0;
    while (number <= secondNum)
    {
        if (number % 2!=0){
            sum += (number * number);
        }
		number++;
    }
	cout << "The sum of the square of the odd numbers between first number and second number: "<<sum<<"\n";
    //f. Output all uppercase letters.
    cout << "\n\nAll uppercase letters.\n";
    int c = 65;
	while (c < 91){
	    cout << char(c++) << ", ";
	}
    cout << "\n";
	cin>>sum;
	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