Welcome to Westonci.ca, your go-to destination for finding answers to all your questions. Join our expert community today! Connect with professionals on our platform to receive accurate answers to your questions quickly and efficiently. Join our Q&A platform to connect with experts dedicated to providing accurate answers to your questions in various fields.

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

a. prompt the user to input two integers: firstNum and secondNum
b. Output all odd numbers between firstNum and secondNum.
c. Output the sum of all even numbers between firstNum and secondNum.
d. Output the number and their squares between 1 and 10
e. Output the sum of the square of the odd numbers between firstNum and secondNum.
f. Output all uppercase letters.

Sagot :

Answer:

Explanation:

//Include the required header files.

#include<iostream>

using namespace std;

//Define the main function.

int main()

{

//Define the variables.

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

char ch;

//Check for valid input.

while (!(firstNum < secondNum))

{

cout << "Enter starting number: ";

cin >> firstNum;

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

cin >> secondNum;

}

//Store first number in i

i = firstNum;

//Dispaly the number.

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

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

//Iterate between first and second number.

while (i <= secondNum)

{

//Check for even numbers.

//Store the sum

if (i % 2 == 0)

sum = sum + i;

//Print the odd numbers

//Evaluate the square of sum of odd number.

else

{

cout << i << " ";

sqSum = sqSum + i * i;

}

//Increase the value of i.

i++;

}

//Dispaly the sum of even numbers.

cout << "\n\nThe sum of the even numbers is:"

<< sum << endl << endl;

//Dispaly the sum of square of odd number.

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

<< sqSum << endl;

//Set i to 1.

i = 1;

//Dispaly the message.

cout << "\nNumber Square\n";

//Iterate and print number between 1 andd 10

//along with the sum.

while (i <= 10)

{

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

i++;

}

//USe for visual studio.

system("pause");

//Return the value 0.

return 0;

}

Explanation:

The program code will perform the function listed below using loop.

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.

Hope this helps!