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....
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...
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...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in Lab 2 to obtain a diameter value from the user and compute the volume of a sphere (we assumed that to be the shape of a balloon) in a new program, and implement the following restriction on the user’s input: the user should enter a value for the diameter which is at least 8 inches but not larger than 60 inches. Using an if-else...
C++ PROGRAMMING Assignment: For this assignment, you will construct a program which is capable of taking...
C++ PROGRAMMING Assignment: For this assignment, you will construct a program which is capable of taking a user-given number, and adding up all of the numbers between 1 and the given number. So if someone inputs 12, it should add 1 + 2 + 3 + 4 + … 9 + 10 + 11 + 12, and return the answer. However, you’ll be using two different methods to do this. The first method should utilize either a for loop or...
Questions: 1. (5 marks) Create a VB.NET Console Application that defines a function Smallest and calls...
Questions: 1. Create a VB.NET Console Application that defines a function Smallest and calls this function from the main program. The function Smallest takes three parameters, all of the Integer data type, and returns the value of the smallest among the three parameters. The main program should (1) Prompt a message (using Console.WriteLine) to ask the user to input three integers. (2) Call the built-in function Console.ReadLine() three times to get the user’s input. (3) Convert the user’s input from...
Python: Simple Banking Application Project Solution: • Input file: The program starts with reading in all...
Python: Simple Banking Application Project Solution: • Input file: The program starts with reading in all user information from a given input file. The input file contains information of a user in following order: username, first name, last name, password, account number and account balance. Information is separated with ‘|’. o username is a unique information, so no two users will have same username. Sample input file: Username eaglebank has password 123456, account number of BB12 and balance of $1000....
Write a C++ program that converts time of day from a 24-hour notation to a 12-hour...
Write a C++ program that converts time of day from a 24-hour notation to a 12-hour notation. For example, it should convert 14:25 to 2:25 PM. (A) The user provides input as two integers separated by ‘:’. The following function prototype should capture the user inputs as described below: void input(int& hours24, int& minutes); //Precondition: input(hours, minutes) is called with //arguments capable of being assigned values. //Postcondition: // user is prompted for time in 24 hour format: // HH:MM, where...
In this assignment you will write a program that compares the relative strengths of two earthquakes,...
In this assignment you will write a program that compares the relative strengths of two earthquakes, given their magnitudes using the moment magnitude scale. Earthquakes The amount of energy released during an earthquake -- corresponding to the amount of shaking -- is measured using the "moment magnitude scale". We can compare the relative strength of two earthquakes given the magnitudes m1 and m2 using this formula: f=10^1.5(m1−m2) If m1>m2, the resulting value f tells us how many times stronger m1...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT