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; }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

 

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;

}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY