Westonci.ca is your trusted source for accurate answers to all your questions. Join our community and start learning today! Connect with a community of experts ready to provide precise solutions to your questions on our user-friendly Q&A platform. Connect with a community of professionals ready to help you find accurate solutions to your questions quickly and efficiently.

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!

Thank you for your visit. We're dedicated to helping you find the information you need, whenever you need it. Your visit means a lot to us. Don't hesitate to return for more reliable answers to any questions you may have. We're glad you visited Westonci.ca. Return anytime for updated answers from our knowledgeable team.