(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;
2. Uses a While Loop;
3. Uses a Do While Loop:
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:
==================
Get Answers For Free
Most questions answered within 1 hours.