Write a program that uses while loops to perform the followi

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

a. Prompt the user to input two integers: firstNum and secondNum (firstNum must be less than 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 numbers 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.

Redo using for loops.

Redo using do...while loops.

Turn in:

Your source code for all three programs with

The name of your program as a comment at the top of the file

Your IPO chart incorporated as comments after the name of the file

A screen shot or picture of the results after running your program with your test data, all three versions should produce the same output with the same test data.

Solution

#include <iostream>
using namespace std;

int main()
{

int firstNum;
int secondNum;
while(1)
{
cout << \"Enter first number: \";
cin >> firstNum;

cout << \"Enter second number greater than second number: \";
cin >> secondNum;

if (firstNum >= secondNum)
{
cout << \"First number should be less than second number. \"<< endl;
cout << \"Please reenter\" << endl;
}
else
{
break;
}
}

int i;
int sumEven;
int sumOddSquares;

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

i = firstNum;
sumEven = 0;
cout << \"Odd numbers: \" ;
while(i < secondNum)
{
if (i % 2 == 0)
{
sumEven += i;
}
i++;
}
cout << \"Sum of even numbers: \" << sumEven << endl;

i = firstNum;
cout << \"Num and their squre between 1 and 10: \" << endl;
while(i < secondNum)
{
if ( i >= 1 && i <= 10)
{
cout << i << \" \" << i*i << endl;
}
i++;
}

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

i = 0;
while(i < 26)
{
char c = \'A\' + i;
cout << c << \" \";
i++;
}
cout << endl;

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

sumEven = 0;
cout << \"Odd numbers: \" ;
for (i = firstNum; i < secondNum; i++)
{
if (i % 2 == 0)
{
sumEven += i;
}
}
cout << \"Sum of even numbers: \" << sumEven << endl;

cout << \"Num and their squre between 1 and 10: \" << endl;
for (i = firstNum; i < secondNum; i++)
{
if ( i >= 1 && i <= 10)
{
cout << i << \" \" << i*i << endl;
}
}

sumOddSquares = 0;
for (i = firstNum; i < secondNum; i++)
{
if ( i % 2 == 1)
{
sumOddSquares += i*i;
}
}
cout << \"Sum of squares of odd numbers: \" << sumOddSquares << endl;

for (i = 0; i < 26; i++)
{
char c = \'A\' + i;
cout << c << \" \";
}
cout << endl;


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

i = firstNum;
sumEven = 0;
cout << \"Odd numbers: \" ;
do
{
if (i % 2 == 0)
{
sumEven += i;
}
i++;
}while(i < secondNum);
cout << \"Sum of even numbers: \" << sumEven << endl;

i = firstNum;
cout << \"Num and their squre between 1 and 10: \" << endl;
do
{
if ( i >= 1 && i <= 10)
{
cout << i << \" \" << i*i << endl;
}
i++;
}while(i < secondNum);

sumOddSquares = 0;
i = firstNum;
do
{
if ( i % 2 == 1)
{
sumOddSquares += i*i;
}
i++;
}while(i < secondNum);
cout << \"Sum of squares of odd numbers: \" << sumOddSquares << endl;

i = 0;
do
{
char c = \'A\' + i;
cout << c << \" \";
i++;
}while(i < 26);
cout << endl;

return 0;
}

Write a program that uses while loops to perform the following steps: a. Prompt the user to input two integers: firstNum and secondNum (firstNum must be less th
Write a program that uses while loops to perform the following steps: a. Prompt the user to input two integers: firstNum and secondNum (firstNum must be less th
Write a program that uses while loops to perform the following steps: a. Prompt the user to input two integers: firstNum and secondNum (firstNum must be less th
Write a program that uses while loops to perform the following steps: a. Prompt the user to input two integers: firstNum and secondNum (firstNum must be less th

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site