45.0k views
3 votes
Write a program that uses while loops to perform the following steps: Step a: Prompt the user to input two integers: firstNum and secondNum (firstNum must be less than secondNum). Step b: Output all odd numbers between firstNum and secondNum. Step c: Output the sum of all even numbers between firstNum and secondNum. Step d: Output the numbers and their squares between 1 and 10. Step e: Output the sum of the square of the odd numbers between firstNum and secondNum. Step f: Output all uppercase letters.

User Delebrin
by
6.0k points

1 Answer

3 votes

Answer:

#include<iostream>

using namespace std;

int main()

{

int i, sum = 0, sqSum = 0, firstNum = 1, secondNum = 0;

char ch;

while (!(firstNum < secondNum))

{

cout << "Enter starting number: ";

cin >> firstNum;

cout<<"Enter ending number(must be > startingNumber): ";

cin >> secondNum;

}

i = firstNum;

cout << "The odd numbers between " << firstNum

<< " and " << secondNum << " are:\\";

while (i <= secondNum)

{

if (i % 2 == 0)

sum = sum + i;

else

{

cout << i << " ";

sqSum = sqSum + i * i;

}

i++;

}

cout << "\\\\The sum of the even numbers is:"

<< sum << endl << endl;

cout << "The sum of squares the odd numbers is:"

<< sqSum << endl;

i = 1;

cout << "\\Number Square\\";

while (i <= 10)

{

cout << " " << i << "\t " << i * i << endl;

i++;

}

system("pause");

return 0;

}

User Codoscope
by
6.5k points