137k views
5 votes
Write a program that uses do while loops to perform the following steps:

a. Prompt the user to input two positive integers. variables: firstNum and secondNum (firstNum must be less than secondNum). Validate the user's input; prompt the user again if firstNum is not less than secondNum (use do while loop).
b. Output all odd numbers between firstNum and secondNum. (use do while loop).
c. Output the sum of all even numbers between firstNum and secondNum. (use do while loop).
d. Output the numbers and their squares between 1 and 10. (use do while loop).
e. Output the sum of the square of the odd numbers between firstNum and secondNum. (use do while loop)
f. Output all uppercase letters. (use do while loop).

Program layout:

int main()

{

//a

do

{

} while()

//b

do

{

} while()

//c

do

{

} while()

//d

do

{

} while()

//e

do

{

} while()

//f

do

{

} while()

}

***You assume that the user types only integer numbers.

***Do not use any pre-defined functions that were not covered in the class.

***Do not use any user-defined functions.

***Use only topics that were covered in the class.

***No object-oriented programming.

***Match the output below.

Submit your source code (file name is Assignment_09_yourLastName.cpp). Make sure that it compiles using Code::Blocks.

If it doesn't compile, you will lose 50%. Improper indentation: -20%

If it doesn't produce the required results: -30%

Do NOT compress the file.

**************************************************************************************

OUTPUTS:

**************************************************************************************

Enter two positive numbers.
First number must be less than the second number:
Enter numbers: 8 2
First number must be less than the second number!
Please try again.

Enter two positive numbers.
First number must be less than the second number:
Enter numbers: -2 8
No negative numbers!
Please try again.

Enter two positive numbers.
First number must be less than the second number:
Enter numbers: 2 8

Odd integers between 2 and 8 are:
3 5 7

Sum of even integers between 2 and 8 = 20

Number Square of Number
1 1
2 4
3 9
4 16
5 25
6 36
7 49
8 64
9 81
10 100

Sum of the squares of odd integers between 2 and 8 = 83

Upper case letters are: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

**************************************************************************************

Enter two positive numbers numbers.
First number must be less than the second number you enter
Enter numbers: 1 9

Odd integers between 1 and 9 are:
1 3 5 7 9

Sum of even integers between 1 and 9 = 20

Number Square of Number
1 1
2 4
3 9
4 16
5 25
6 36
7 49
8 64
9 81
10 100

Sum of the squares of odd integers between 1 and 9 = 165

Upper case letters are: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

**************************************************************************************

Enter two positive numbers numbers.
First number must be less than the second number you enter
Enter numbers: 11 15

Odd integers between 11 and 15 are:
11 13 15

Sum of even integers between 11 and 15 = 26

Number Square of Number
1 1
2 4
3 9
4 16
5 25
6 36
7 49
8 64
9 81
10 100

Sum of the squares of odd integers between 11 and 15 = 515

Upper case letters are: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

************************************************************************************************

I NEED HELP THIS IS WHAT I HAVE SO FAR

#include
using namespace std;

int main()
{
int firstNum, secondNum;

do
{
cout << "Enter Two Positive Numbers. " << endl;
cout << "First Number Must Be Less Than The Second Number: " << endl;
cin >> firstNum >> secondNum;

{
if(firstNum <= 0 || secondNum <= 0)
{
cout << "No negative numbers!" << endl;
}
else if(firstNum > secondNum)
{
cout << "First number must be less than the second number!" << endl;
cout << "Please try again." << endl;
}
}
}while(firstNum > secondNum);

int i= firstNum;

cout << "\\Odd numbers between " << firstNum << " and " << secondNum << " are:";

if(firstNum % 2 == 0 )

i = firstNum + 1;

do
{
cout< i = i+2;
}while(i
i = firstNum;

int sum = 0;

do
{
if(i%2 == 0)
sum = sum + i;

}while(i
cout<<"\\ Sum of all even numbers between "< cout<<"\\Squares if number between 1 and 10 are: ";

i = 1;

while(i < 11)
{
cout< }

i = firstNum;
sum = 0;
do
{
if(i % 2 ==1)
{
sum = sum + (i*i);
}

cout << "Upper case letters are: ";

i = 0;
}while(i < 26);
{
char start = 'A';
cout << char(start + i) << " ";
i++;
}
return 0;
}

1 Answer

4 votes

Answer:

a. Prompt the user to input two positive integers. variables: First and Second (First must be less than Second). Validate the user's input; prompt the user again if First is not less than Second (use do while loop).

User Tristan Djahel
by
4.1k points