Please answer number 10 in C++ 8. 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. C9282_chapter05_hr.indd 341 1/11/17 7:42 PM342 | Chapter 5: Control Structures II (Repetition) e. Output the sum of the square of the odd numbers between firstNum and secondNum. f. Output all uppercase letters. 9. Redo Programming Exercise 8 using for loops. 10. Redo Programming Exercise 8 using do...while loops. this is my code #include #include using namespace std; int main() { int firstNum, secondNum; int sumEven = 0; int counter, start, sumSquareOdd = 0; char chCounter; //part a cout << " Enter first positive integer: " << endl; cin >> firstNum; cout << " Enter second positive integer (greater than firstNum): " << endl; cin >> secondNum; //Part b if (firstNum % 2 == 0) start = firstNum + 1; else start = firstNum; cout << " Odd Numbers: "; for (counter = start; counter <= secondNum; counter = counter + 2) cout << counter << " "; //Part c for (counter = start - 1; counter <= secondNum; counter = counter + 2) sumEven = counter + sumEven; cout << "\n The sum of even numbers: " << sumEven << endl; //Part d cout << " Numbers and square are: " << endl; for (counter = 1; counter <= 10; counter = counter + 1) cout << counter << " " << counter * counter << endl; //Part e if (firstNum % 2 == 0) start = firstNum + 1; else start = firstNum; for (counter = start; counter <= secondNum; counter = counter + 2) sumSquareOdd = sumSquareOdd + counter * counter; cout << " Sum of the squares of odd integers between " << firstNum << " and " << secondNum << " = " << sumSquareOdd << endl; //Part f cout << " Upper case letters are: "; for (chCounter = 'A'; chCounter <= 'Z'; chCounter++) cout << chCounter << ""; cout << endl; return 0; }
Please answer number 10 in C++
8. 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.
C9282_chapter05_hr.indd 341 1/11/17 7:42 PM342 | Chapter 5: Control Structures II (Repetition)
e. Output the sum of the square of the odd numbers between
firstNum and secondNum.
f. Output all uppercase letters.
9. Redo Programming Exercise 8 using for loops.
10. Redo Programming Exercise 8 using do...while loops.
this is my code
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int firstNum, secondNum;
int sumEven = 0;
int counter, start, sumSquareOdd = 0;
char chCounter;
//part a
cout << " Enter first positive integer: " << endl;
cin >> firstNum;
cout << " Enter second positive integer (greater than firstNum): " << endl;
cin >> secondNum;
//Part b
if (firstNum % 2 == 0)
start = firstNum + 1;
else
start = firstNum;
cout << " Odd Numbers: ";
for (counter = start; counter <= secondNum; counter = counter + 2)
cout << counter << " ";
//Part c
for (counter = start - 1; counter <= secondNum; counter = counter + 2)
sumEven = counter + sumEven;
cout << "\n The sum of even numbers: " << sumEven << endl;
//Part d
cout << " Numbers and square are: " << endl;
for (counter = 1; counter <= 10; counter = counter + 1)
cout << counter << " " << counter * counter << endl;
//Part e
if (firstNum % 2 == 0)
start = firstNum + 1;
else
start = firstNum;
for (counter = start; counter <= secondNum; counter = counter + 2)
sumSquareOdd = sumSquareOdd + counter * counter;
cout << " Sum of the squares of odd integers between " << firstNum << " and " << secondNum << " = " << sumSquareOdd << endl;
//Part f
cout << " Upper case letters are: ";
for (chCounter = 'A'; chCounter <= 'Z'; chCounter++)
cout << chCounter << "";
cout << endl;
return 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images