BELOW ARE THREE PROGRAMS CAN YOU MAKE A MENU SO IT ASKS THE USER TO ENTER EITHER
ID: 3539210 • Letter: B
Question
BELOW ARE THREE PROGRAMS CAN YOU MAKE A MENU SO IT ASKS THE USER TO ENTER EITHER 1,2 OR 3 AND THE PROGRAM WILL RUN ACCORDINGLY //PROGRAM 1: #include using namespace std; int main() { int a; int b; int c; cout<<"Hours worked "; cin>>a; cout<<"pay per hour "; cin>>b; if(a<=20){ c=a*b; cout<<"total pay="; cout<>asterick; //This if statement check if the number is valid and prints "*" n times if(asterick < 5 || asterick > 25) { cout<<"Invalid output please try again "< using namespace std; int main(){ int asterick; //for loop will ask for 5 valid inputs and print "*" n times for(int i = 0; i<5; i++) { cout << "Enter number between 5-25 " << endl; //Read input cin >>asterick; //This if statement check if the number is valid and prints "*" n times if(asterick < 5 || asterick > 25) { cout<<"Invalid output please try again "<Explanation / Answer
#include<iostream>
using namespace std;
int menu()
{
int num;
cout << "1. Enter 1 to run program 1 " << endl;
cout << "2. Enter 2 to run program 2 " << endl;
cout << "3. Enter 3 to run program 3 " << endl;
cout << "3. Enter 4 to run program 4 " << endl;
cout << "3. Enter 5 to run program 5 " << endl;
cout << "3. Enter 6 to run program 6 " << endl;
cin >> num;
return num;
}
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
void printLineNumber(int n)
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<i;j++)
cout<<" ";
cout<<i<<endl;
}
}
void program_1()
{
int n;
cout<<"Enter number of lines: ";
cin>>n;
printLineNumber(n);
}
void program_2()
{
int asterick;
//for loop will ask for 5 valid inputs and print "*" n times
for(int i = 0; i<5; i++)
{
cout << "Enter number between 5-25 " << endl;
//Read input
cin >>asterick;
//This if statement check if the number is valid and prints "*" n times
if(asterick < 5 || asterick > 25)
{
cout<<"Invalid output please try again "<<endl;
i--;
}
else
{
for(int j = 0; j < asterick; j++)
cout<<"*";
}
cout<<" ";
}
}
void program_3()
{
short ab,bal,ch,dep;
cout<<"enter account number";cin>>ab;
cout<<endl<<"enter balance";cin>>bal;
cout<<endl<<"total of all checks";cin>>ch;
cout<<endl<<"total deposits";cin>>dep;
bal=bal-ch+dep;
if(bal<0)
{
cout<<endl<<"you are debited with $17.50";
bal=bal-17.5;
}
}
void program_4()
{
int a;
int b;
int c;
cout<<"Hours worked ";
cin>>a;
cout<<"pay per hour ";
cin>>b;
if(a<=20){
c=a*b;
cout<<"total pay=";
cout<<c;
}else if(20<a<=40){
c=(a*b)+(((a-20)*b)/2);
cout<<"total pay=";
cout<<c;
}else
{c=(a*b)+(10*b)+((a-40)*b);
cout<<"total pay=";
cout<<c;
}
}
void program_5()
{
//Declarations
float charge;
int hours;
char package;
char tmp[10];
//ask user
while(true)
{
cout<<"Enter Package type: a,b or c: ";
cin>>tmp;
package=tmp[0];
if(package=='a' || package=='b' || package=='c')
break;
cout<<"Wrong package. Must be either a, b or c. Please try again"<<endl;
}
//Get hours
while(true)
{
cout<<"Enter number of hours: ";
cin>>hours;
if(hours>0)
break;
cout<<"Hours value must be positive. Please try again"<<endl;
}
//calculate charge
switch(package)
{
case 'a':
charge=29.95;
if(hours>11 && hours<=22)
charge+=(hours-11)*2.5;
if(hours>22)
charge+=(11*2.5)+((hours-22)*5.0);
break;
case 'b':
charge=34.95;
if(hours>22 && hours<=33)
charge+=(hours-22)*1.25;
if(hours>33)
charge+=(11*1.25)+((hours-33)*2.5);
break;
case 'c':
charge=39.95;
break;
default:
charge=0;
}
//output
cout.precision(2);
cout<<fixed<<"Monthly charge is $"<<charge<<endl;
}
void program_6()
{
int i=1,cou=0;
while(1)
{
if(i%2==0 || i%3==0 || i%5==0)
cou++;
if(cou==1500)
{
cout<<"the ugly number is "<<i;
return;
}
i++;
}
}
int main()
{
int input = menu();
switch(input)
{
case 1:program_1(); break;
case 2:program_2(); break;
case 3:program_3(); break;
case 4:program_4(); break;
case 5:program_5(); break;
case 6:program_6(); break;
default: cout << " Invalid input " << endl;
}
cout << endl;
cout << endl;
system("pause");
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.