Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++. Write a program that uses for loops to perform the following steps: a. Prom

ID: 3857571 • Letter: C

Question

C++. Write a program that uses for 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 for loop).
b. Output all odd numbers between firstNum and secondNum. (use for loop).
c. Output the sum of all even numbers between firstNum and secondNum. (use for loop).
d. Output the numbers and their squares between 1 and 10. (use for loop).
e. Output the sum of the square of the odd numbers between firstNum and secondNum. (use for loop)
f. Output all uppercase letters. (use for loop).

Program layout:

int main()

{

//a

for()

{

}

//b

for()

{

}

//c

for()

{

}

//d

for()

{

}

//e

for()

{

}

//f

for()

{

}

}

OUTPUTS:

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

Enter two positive integer 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 integer numbers.
First number must be less than the second number:
Enter numbers:

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

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


No negative numbers!
Please try again.

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

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

Enter two positive integer numbers.
First number must be less than the second number you enter
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 integer 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 integer 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

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

Explanation / Answer

#include <iostream>
using namespace std;

int main()
{
int a,b,i,sum,sumo,k; //variabele declaration
sum=0;
sumo=0;
do
{
cout<<"Enter two positive integer numbers"<<endl; //accepting number from user
cin>>a;
cin>>b;
if(a>b && a>0 && b>0) //checking if first is always less than second
{
cout<<"First number must be less than the second number!"<<endl;
cout<<"Please try again."<<endl;
}
if(a<0 || b<0) //check for negative numbers
{
cout<<"No Negative Numbers"<<endl;
cout<<"Please try again"<<endl;
}
}while(a>b || a<0 || b<0);
cout<<"Odd integers between "<<a<<" and "<<b<<" are:"<<endl;
for(i=a;i<=b;i++) //printing odd numbers between the range
{
if(i%2==1)
cout<<" "<<i;
}
cout<<endl;
for(i=a;i<=b;i++) //calcultaing the sum of even numbers between the range
{
if(i%2==0)
sum=sum+i;
}
cout<<"Sum of even integers between "<<a<<" and "<<b<<" is:"<<sum<<endl;
cout<<"Number"<<" "<<"Square of Number"<<endl;
for(i=1;i<=10;i++)
{
cout<<i<<" "<<(i*i)<<endl; //printint the number and its square
}
for(i=a;i<=b;i++)
{
if(i%2==1)
{
k=i*i;
sumo=sumo+k; //calculating the sum of square odd numbers beteen the range
}
}
cout<<"Sum of the squares of odd integers between "<<a<<" and "<<b<<" = "<<sumo<<endl;
for(i=65;i<91;i++)
cout<<char(i); //printing all the uppercase charecter.
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote