Homework Help Question & Answers

My if/else statement wont run the program that I am calling. The menu prints but once...

My if/else statement wont run the program that I am calling. The menu prints but once I select a number the menu just reprints, the function called wont run. What can I do to fix this probelm?

#include <iostream>

#include "miltime.h"

#include "time.h"

#include "productionworker.h"

#include "employee.h"

#include "numdays.h"

#include "circle.h"

using namespace std;

int main() {

int select=1;

 

 

while (select>0)

{

cout << "Option 1:Circle Class\n"<< endl;

cout << "Option 2:NumDay Class\n" << endl;

cout <<"Option 3:Employee and Production Worker Class \n"<< endl;

cout <<"Option 4:Time Format \n"<< endl;

cout <<"Option (-1): EXIT\n" << endl;

cout << "Please enter option number to run program\n"<< endl;

cin >> select;

}

if (select==1)

{

Circle c;

double r;

cout << "Enter the radius of the circle"<<endl;

cin>>r; c.setRadius(r);

cout<<"Area of the circle: "<< c.getArea()<<endl;

cout <<"Diameter of the circle: "<< c.getDiameter ()<<endl;

cout <<"Circumference of the circle: "<< c.getCircum()<<endl;

return 0;

}

if (select ==2)

{

NumDays X(12), Y(8), Z, add, sub;

add=X+Y;

sub=X-Y;

cout<<"The Addition Operator + : "<<add.getDays()<<endl;

cout<<"The Subtraction Operator - : "<<sub.getDays()<<endl;

}

 

else if (select==3)

{

int shift;

double pay;

cout<<"1-DayShift \n2-Night " <<endl;

cout<<"Enter Shift";

cin>>shift;

cout<<"Enter hourly pay:";

cin>>pay;

ProductionWorker emp1(shift,pay);

emp1.setEmpName ("Maria");

emp1.setEmpNumber(313329);

emp1.setHireDate("February 3, 2013");

 

cout<<"Employee Details:" <<endl<<endl;

cout <<"Employee Name: "<< emp1.getEmpName()<<endl;

cout<<"Employee Number: "<<emp1.getEmpNumber()<<endl;

cout<<"Employee Hire Date: "<< emp1.getHireDate()<<endl;

cout<<"Employee Shift: "<< emp1.getShift()<<endl;

cout<<"Employee Hourly Pay: "<<emp1.getHourlyPay()<<endl;

return 0;

}

else if (select ==4)

{int hr, sec;

MilTime time1(0,0);

cout << "Enter Time in Military Format: ";

cin >> hr;

sec=hr%10;

time1.setTime (hr,sec);

cout<<"Military Format: " << time1.getHour()<<"hours"<<endl;

if (time1.gethour()/12==1)

{

cout<<"Standard Format: " <<time1.getStandHr()<<" : ";

if (time1.getMin()==0)

cout <<time1.getMin()<< "0"<< "PM"<< endl;

else cout<<time1.getMin()<<"PM"<<endl;

}

else

cout<<"Standard Format: "<<time1.getStandHr()<< " : ";

if (time1.getMin()==0)

{

cout<<time1.getMin()<<"0"<<"AM"<<endl;

}

else

cout<<time1.getMin()<<"AM"<<endl;

}

else if (select== -1)

{

cout<<"Program Exit\n"<<endl;

}

else

cout<<"Invalid Entry!\n"<<endl;

select= 1;

 

}

 

0 0
Add a comment
Answer #1

you\;have\;to\;put\;these\;if/else\;statements\;inside\;the\;while\;loop

_______________________________________________________________________________________________

#include <iostream>
#include "miltime.h"
#include "time.h"
#include "productionworker.h"
#include "employee.h"
#include "numdays.h"
#include "circle.h"
using namespace std;

int main() {

   int select = 1;

   while (select > 0)
   {
       cout << "Option 1:Circle Class\n" << endl;

       cout << "Option 2:NumDay Class\n" << endl;

       cout << "Option 3:Employee and Production Worker Class \n" << endl;

       cout << "Option 4:Time Format \n" << endl;

       cout << "Option (-1): EXIT\n" << endl;

       cout << "Please enter option number to run program\n" << endl;

       cin >> select;
       if (select == 1)

       {
           Circle c;
           double r;
           cout << "Enter the radius of the circle" << endl;
           cin >> r; c.setRadius(r);

           cout << "Area of the circle: " << c.getArea() << endl;
           cout << "Diameter of the circle: " << c.getDiameter() << endl;
           cout << "Circumference of the circle: " << c.getCircum() << endl;
           return 0;

       }

       if (select == 2)

       {
           NumDays X(12), Y(8), Z, add, sub;
           add = X + Y;
           sub = X - Y;
           cout << "The Addition Operator + : " << add.getDays() << endl;
           cout << "The Subtraction Operator - : " << sub.getDays() << endl;

       }


       else if (select == 3)
       {
           int shift;
           double pay;
           cout << "1-DayShift \n2-Night " << endl;
           cout << "Enter Shift";
           cin >> shift;
           cout << "Enter hourly pay:";
           cin >> pay;
           ProductionWorker emp1(shift, pay);
           emp1.setEmpName("Maria");
           emp1.setEmpNumber(313329);
           emp1.setHireDate("February 3, 2013");


           cout << "Employee Details:" << endl << endl;
           cout << "Employee Name: " << emp1.getEmpName() << endl;
           cout << "Employee Number: " << emp1.getEmpNumber() << endl;
           cout << "Employee Hire Date: " << emp1.getHireDate() << endl;
           cout << "Employee Shift: " << emp1.getShift() << endl;
           cout << "Employee Hourly Pay: " << emp1.getHourlyPay() << endl;
           return 0;

       }

       else if (select == 4)
       {
           int hr, sec;
           MilTime time1(0, 0);
           cout << "Enter Time in Military Format: ";
           cin >> hr;
           sec = hr % 10;
           time1.setTime(hr, sec);
           cout << "Military Format: " << time1.getHour() << "hours" << endl;
           if (time1.gethour() / 12 == 1)
           {

               cout << "Standard Format: " << time1.getStandHr() << " : ";

               if (time1.getMin() == 0)

                   cout << time1.getMin() << "0" << "PM" << endl;

               else cout << time1.getMin() << "PM" << endl;

           }
           else

               cout << "Standard Format: " << time1.getStandHr() << " : ";

           if (time1.getMin() == 0)
           {
               cout << time1.getMin() << "0" << "AM" << endl;

           }
           else
               cout << time1.getMin() << "AM" << endl;

       }

       else if (select == -1)
       {
           cout << "Program Exit\n" << endl;
       }
       else

           cout << "Invalid Entry!\n" << endl;
       select = 1;
   }


}

Add a comment
Know the answer?
Add Answer to:
My if/else statement wont run the program that I am calling. The menu prints but once...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coin

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need help with a program. My program wont run. I cant fix the errors. Its...

    I need help with a program. My program wont run. I cant fix the errors. Its mainly c++. I am trying to run it in dev c++. if anyone can fix this program i will be glad. #include <iostream> #include <fstream> #include <string> #include <vector> #include <map> #include <iomanip> #include <algorithm> #include <stdlib.h> #include <time.h> using namespace std; bool buildMap(); void writeIndex(); void AddWordtoMap(string); void writeSorted(); void Filter(); map <string, int> jobMap; map <string, int> filterMap; typedef pair<string, int> myPair;...

  • I am trying to run this program in Visual Studio 2017. I keep getting this build...

    I am trying to run this program in Visual Studio 2017. I keep getting this build error: error MSB8036: The Windows SDK version 8.1 was not found. Install the required version of Windows SDK or change the SDK version in the project property pages or by right-clicking the solution and selecting "Retarget solution". 1>Done building project "ConsoleApplication2.vcxproj" -- FAILED. #include <iostream> #include<cstdlib> #include<fstream> #include<string> using namespace std; void showChoices() { cout << "\nMAIN MENU" << endl; cout << "1: Addition...

  • I'm just a beginner in programming,how to make this program more simple without using #include<iostream> and #include<redex> here is the question Terms to know: If-else statement,for.....

    I'm just a beginner in programming,how to make this program more simple without using #include<iostream> and #include<redex> here is the question Terms to know: If-else statement,for..while..do while,loops,pointer,address,continue,return,break. Create a C++ program which contain a function to ask user to enter user ID and password. The passwordmust contain at least 6 alphanumeric characters, 1 of the symbols [email protected],#,$,%,^,&,* and 1 capital letter.The maximum allowable password is 20. Save the information. Test the program by entering the User ID and password. The...

  • // I am going to use if and else stamtents for this employee pay clalulations. //using...

    // I am going to use if and else stamtents for this employee pay clalulations. //using if and else to cal salary //If hours worked is <= 40.0 //Employee salry will = hours*pay rate //else //employess salary will =40*pay rate +(hours worked-40)*1.5* pay rate. #include using namespace std; const double Max_Hours= 40.0; const double MuLTIPLER = 1.5; char salary; char payrate; char hours_worked; char Max_hours; char get_total_pay; int main() { double Hours=0; double Payrate = 0; cout <<"Please enter employee...

  • When I try to run the program it gives me an erron saying Expected expresion on...

    When I try to run the program it gives me an erron saying Expected expresion on this line, else if(phrase.find(sub_String)!=std::string::npos). #include #include #include using namespace std;    int main( ) {          // Defining variables. //Initilizing variables. int magicNum; int magicNum1; int position; int phraseLenght; string vowels = "aeiou"; string phrase; string sub;       // The phrase and the sub phrase cout << "Enter a phrase:" << endl; std::getline (std::cin,phrase);    cout << "Enter a 3-character sub:"...

  • I'm having an error with my program This is the error that I am getting: error:...

    I'm having an error with my program This is the error that I am getting: error: no match for 'operator!=' (operand types are 'std::__cxx11::string {aka std::__cxx11::basic_string<char>}' and 'char') while (postfixInput != 'q') Not sure how to fix it or to write it another way. Here's my program: #include <iostream> #include <string> #include <stack> using namespace std; //Function to calculate operand and use switch case int calculation(int operand1, int operand2, char operation) { switch(operation){ case '+' :return operand2+operand1; case '-' :return...

  • Why am I getting the same results with my rand() every time I run my C++...

    Why am I getting the same results with my rand() every time I run my C++ program? I am trying to do this problem: each receive $200 per week plus 9 percent of their gross sales for that week. For example, a salesperson who grosses $5000 in sales in a week receives $200 plus 9 percent of $ 5000, or a total of $650. Write a program(using an array of counters) that determines how many of the salespeople earned salaries...

  • fully comments for my program, thank you will thumb up #include <iostream> #include <fstream> #include <string>...

    fully comments for my program, thank you will thumb up #include <iostream> #include <fstream> #include <string> #include <iomanip> using namespace std; struct book { int ISBN; string Author; string Title; string publisher; int Quantity; double price; }; void choice1(book books[], int& size, int MAX_SIZE) { ifstream inFile; inFile.open("inventory.txt"); if (inFile.fail()) cout <<"file could not open"<<endl; string str;    while(inFile && size < MAX_SIZE) { getline(inFile, str); books[size].ISBN = atoi(str.c_str()); getline(inFile, books[size].Title);    getline(inFile, books[size].Author); getline(inFile, books[size].publisher);          getline(inFile,...

  • c++pseudocode of this program

    Dear,// utilities.h (header file)#include <iostream>#include <iomanip>using namespace std;#define MANAGER_PAY 700.0#define SUPERVISOR_PAY 600.0#define EMPLOYEE_PAY 500.0#define SINGLE_INS_RATE 0.02#define SING_WITH_CHILD_INS_RATE 0.03#define MARRIED_INS_RATE 0.04#define MARRIED_WITH_CHILD_INS_RATE 0.05#define MEDICAL_AMOUNT 100.0#define SOCIAL_SECURITY_AMOUNT_RATE 0.05// returns employee pay based on employee positiondouble getEmployeePay(char empPosition){switch(empPosition){case 'm': return MANAGER_PAY;case 's': return SUPERVISOR_PAY;case 'e': return EMPLOYEE_PAY;}}// determines and return bonus of employee for given gross paydouble determineBonus(double grossPay){if(grossPay >= 12000)return 1000.0;else if(grossPay <= 11999 &&grossPay >= 9000)return 600.0;elsereturn 0;}// calcuates and return tax based on gross paydouble calculateTax(double grossPay){if(grossPay >= 7000)return grossPay...

  • Trying to figure out how to complete my fourth case 4 (option exit), write a function...

    Trying to figure out how to complete my fourth case 4 (option exit), write a function that display a “Good Bye” message and exits/log out from user’s account displaying a menu (sign in, balance, withdraw and exit.. #include<iostream> #include <limits> using namespace std; void printstar(char ch , int n); double balance1; int main() { system("color A0"); cout<<"\n\t\t ========================================="<< endl; cout<<"\t\t || VASQUEZ ATM SERVICES ||"<< endl; cout<<"\t\t ========================================\n\n"<< endl; int password; int pincode ; cout<<" USERS \n"; cout<<" [1] -...

Free Homework App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.