Question

(Use C++ language) Create a program, named threeTypesLoops.cpp, that does the following; 1. Uses a For...

(Use C++ language)

Create a program, named threeTypesLoops.cpp, that does the following;

1. Uses a For Loop that asks for a number between 1 and 10;

  • Will double the number each time through the loop and display the answer.
  • Will run five times, so the number will have been doubled five times, and the answer displayed five times.
  • After the loop, display a message saying 'It's done!'.

2. Uses a While Loop;

  • Ask the user to input a friend's name.
  • Display the sentence: <name> is a friend of yours.
  • Have the loop run three times.

3. Uses a Do While Loop:

  • Ask the user to input the number of hours they worked in a week.
  • Compute their gross pay (before taxes) by multiplying their hours times the constant float RATE of 15.50.
  • Compute their taxes by multiplying their gross pay times the constant float TAX_RATE of .2.
  • Compute their net pay by subtracting their taxes from their gross pay.
  • Display their gross pay, taxes, and net pay in separate sentences, describing what each represents.
  • Ask the user if they have another week of hours. If they enter something other than 'y', exit the loop, and display "Have a nice day!".

Homework Answers

Answer #1

Code is Given Below:

=======================

#include <iostream>
#define RATE 15.50
#define TAX_RATE .2
using namespace std;
int main()
{ int num;
//part 1
for(int i=0;i<5;i++){
//asking user for number
cout<<"Enter a number between 1 and 10 : ";
cin>>num;
num=num*2;
//display result
cout<<"Answer is "<<num<<endl;
}

cout<<"It\'s done!"<<endl;
int j=0;
//part 2
string name;
while(j<3){
//asking user for name
cout<<"Enter your friend\'s name : ";
cin>>name;
//display result
cout<<name<<" is a friend of yours"<<endl;
j++;}
//part 3
int hours;
char option;
float grossPay,tax,netPay;
do{
//asking user for input
cout<<"Enter number of hours you worked in a week : ";
cin>>hours;
//calculating results
grossPay=hours*RATE;
tax=grossPay*TAX_RATE;
netPay=grossPay-tax;
//display data
cout<<"Gross Pay : "<<grossPay<<endl;
cout<<"Tax : "<<tax<<endl;
cout<<"Net Pay : "<<netPay<<endl;
cout<<"Have another week of hour (y/n): ";
cin>>option;}
while(option=='y' || option=='Y');
return 0;}

Output:

---------------

Code Snapshot:

==================

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Create a new file named quiz_loops.py. b. Write your name and date in a comment. c....
Create a new file named quiz_loops.py. b. Write your name and date in a comment. c. Write a for loop which will display this set of values 2,4,6,8,10,12,14,16. d. Write a while which will display this set of values 16,13,10,7,4,1,-2. e. Write a for loop which will print ‘Loops are fun’ three times. f. Write a while loop that will prompt you for four numbers. Convert the number to an integer. Compute the power as power = power ** number....
Write a program which: Write a program which uses the following arrays: empID: An array of...
Write a program which: Write a program which uses the following arrays: empID: An array of 7 integers to hold employee identification numbers. The array should be initialized with the following values: 1, 2, 3, 4, 5, 6, 7. Hours: an array of seven integers to hold the number of hours worked by each employee. payRate: an array of seven doubles to hold each employee’s hourly pay rate. Wages: an array of seven doubles to hold each employee’s gross salary....
In C programming language please. -Construct a program that will make use of user defined functions,...
In C programming language please. -Construct a program that will make use of user defined functions, the do/while loop, the for loop and selection. -Using a do/while loop, your program will ask/prompt the user to enter in a positive value representing the number of values they wish to have processed by the program or a value to quit/exit. -If the user enters in a 0 or negative number the program should exit with a message to the user indicating they...
intructions: please don't use struture and pointers Write a program that displays a weekly payroll report....
intructions: please don't use struture and pointers Write a program that displays a weekly payroll report. A loop in the program should ask the user for the employee number, gross pay, state tax, federal tax, and FICA withholdings. The loop will terminate when 0 is entered for the employee number. After the data is entered, the program should display totals for gross pay, state tax, federal tax, FICA withholdings, and net pay. Input Validation: Do not accept negative numbers for...
C++ Create a program that will use pointers to determine the average (to 1 decimal place)...
C++ Create a program that will use pointers to determine the average (to 1 decimal place) of a series of grades entered into an array. You can assume a maximum of 15 students and the user will end input with a sentinel value. Make sure to use pointer increment and a pointer comparison while loop, and not array notation or array index numbers or offsets. You will use a function called getgrades. Send the array name (a pointer constant) to...
Write a program (C language) that will read the number of a month and will print...
Write a program (C language) that will read the number of a month and will print the number of days in the month. Ignore leap years. Use 28 days for February. Have the program runs in a continuous loop, allowing the user to enter a month number, see that number of days, and repeat. Use month number = 0 to exit the loop and the program. Program must meet the following criteria: 1.Your name and the name of the program...
Create a flowgorithm program to calculate the Area of Circle first then do the Circumference of...
Create a flowgorithm program to calculate the Area of Circle first then do the Circumference of Circle. The user will have the ability to convert Area OR the Circumference. That means we need to add a decision structure to the program. Furthermore, they need to be able to do it as many times as they want. That means we need to add a main loop structure to the program. The user will also have the choice of whether to run...
Phone number lookup Design a program that has two parallel arrays: a string array named people...
Phone number lookup Design a program that has two parallel arrays: a string array named people that is initialized with the names of seven of your friends, and a string array named phoneNumbers that is initialized with your friends phone numbers. The program should allow the user to enter a persons name (or part of a persons name). it should then search for that person in the people array. If the person is found, it should get that persons phjone...
Create a C# application You are to create a class object called “Employee” which included eight...
Create a C# application You are to create a class object called “Employee” which included eight private variables: firstN lastN dNum wage: holds how much the person makes per hour weekHrsWkd: holds how many total hours the person worked each week. regHrsAmt: initialize to a fixed amount of 40 using constructor. regPay otPay After going over the regular hours, the employee gets 1.5x the wage for each additional hour worked. Methods:  constructor  properties  CalcPay(): Calculate the regular...
Create a Java Program/Class named MonthNames that will display the Month names using an array. 1....
Create a Java Program/Class named MonthNames that will display the Month names using an array. 1. Create an array of string named MONTHS and assign it the values "January - December". All 12 months need to be in the array with the first element being "January", then "February", etc. 2. Using a loop, prompt me to enter an int variable of 1-12 to display the Month of the Year. Once you have the value, the program needs to adjust the...