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

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

ID: 3859685 • Letter: W

Question

Write a program that uses 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); create a user-defined function called void validateUserInput(). Use Call-by-Reference.


b. Output all odd numbers between firstNum and secondNum. (use while loop); create a user-defined function called void oddNumbers(). Use Call-by-Reference.


c. Output the sum of all even numbers between firstNum and secondNum. (use while loop); create a user-defined function called void sumEvenNumbers(). Use Call-by-Reference. Declare a variable called sumEven in the main() to store the sum of all even numbers.


d. Output the numbers and their squares between 1 and 10. (use while loop): create a user-defined function called void displaySquareNumbers(). Call-by-Reference.


e. Output the sum of the square of the odd numbers between firstNum and secondNum. (use while loop); create a user-defined function called void sumSqureOddNumbers(). Use Call-by-Reference. Declare a variable called sumSquareOdd in the main() to store the sum of the square of the odd numbers.


f. Output all uppercase letters. (use while loop); create a user-defined function called void displayUppercaseLetters(). Use Call-by-Reference.

Program layout:

int main()

{

//a

validateUserInput();

//b

oddNumbers();

//c

sumEvenNumbers();

//d

displaySquareNumbers();

//e

sumSqureOddNumbers();

//f

displayUppercaseLetters();

}

***Collect the user's inputs in the main() and pass them to the other functions.

***Validate the user's inputs; in case the user types characters.

***Allow the user to use upper case or lower case.

***Allow the user to repeat the program. (use while loop).

OUTPUTS:

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

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


Incorrect Input.
Please try again.

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

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


Incorrect Input.
Please try again.

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

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: -2 8


No negative numbers!
Please try again.

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

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

Do you want to repeat this program?
y/n
> y

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

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

Do you want to repeat this program?
y/n
> y

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

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

Do you want to repeat this program?
y/n
> n

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

Explanation / Answer

#include <stdio.h>

//using namespace std;

void main()
{
int firstNum, secondNum;
int sumEvenNum = 0;
int sumSquareOddNum = 0;
char chCounter;
int counter;
  
//Part a
printf("Enter two numbers. ");
printf("First number must be less than ");
printf("the second number you enter ");
printf("Enter numbers: ");
scanf("%d %d", &firstNum, &secondNum);
while (firstNum > secondNum) {
printf("Sorry invalid input, Please try again, Enter numbers: ");
scanf("%d %d", &firstNum, &secondNum);
}

//Part b
printf("Odd integers between %d and %d are: ",firstNum,secondNum);
counter = firstNum;
while (counter <= secondNum) {
if (counter % 2 == 1) {
printf("%d ", counter);
}
counter++;
}

printf(" ");

//Part c
counter = firstNum;
while (counter <= secondNum) {
if (counter % 2 == 0) {
sumEvenNum = sumEvenNum + counter;
}
counter++;
}

printf("Sum of even integers between %d and %d = %d ", firstNum, secondNum, sumEvenNum);

//Part d
printf("Number Square from 1 to 10 are: ");
counter = 1;
while (counter <= 10)
{
printf("%d : %d ", counter, counter * counter);
counter++;
}


//Part e
if (firstNum % 2 == 0)
counter = firstNum + 1;
else
counter = firstNum;

while (counter <= secondNum)
{
sumSquareOddNum = sumSquareOddNum + counter * counter;
counter = counter + 2;
}

printf("Sum of the squares of odd integers between %d and %d = %d ",firstNum,secondNum,sumSquareOddNum);

//Part f
printf("Upper case letters are: ");

chCounter = 'A';
while (chCounter <= 'Z')
{
printf("%c ", chCounter);
chCounter++;
}
printf(" ");
}

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