Question

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 Improve this question Transcribed image text
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 Coins

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 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...

  • My C++ code won't loop like it should. What am I doing wrong? #include <iostream> using...

    My C++ code won't loop like it should. What am I doing wrong? #include <iostream> using namespace std; int main() {    int n;    int flag= 1;    cout << "Prime/Not Prime" << endl;    cout << "Enter the Number to check Prime:" << endl;    cin >> n;    int m = n / 2;    int i;    for (i = 2; i <= m; i++)        if (n % i == 0)           ...

  • 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 !.@,#,$,%,^,&,* 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...

  • Hey, so i am trying to have my program read a text file using a structure...

    Hey, so i am trying to have my program read a text file using a structure but i also want to be able to modify the results(I kinda have this part but it could be better). I cant seem to get it to read the file(all the values come up as 0 and i'm not sure why because in my other program where it wrote to the txt file the values are on the txt file) i copied and pasted...

  • c++, I am having trouble getting my program to compile, any help would be appreciated. #include...

    c++, I am having trouble getting my program to compile, any help would be appreciated. #include <iostream> #include <string> #include <string.h> #include <fstream> #include <stdlib.h> using namespace std; struct record { char artist[50]; char title[50]; char year[50]; }; class CD { //private members declared private: string artist; //asks for string string title; // asks for string int yearReleased; //asks for integer //public members declared public: CD(); CD(string,string,int); void setArtist(string); void setTitle(string); void setYearReleased(int); string getArtist() const; string getTitle() const; int...

  • I am working on this switch program everything seems to be ok but the compiler is...

    I am working on this switch program everything seems to be ok but the compiler is giving me an error on the final closing brace and wanted to know where I am making an error #include <iostream> #include <iomanip> #include <cmath> using namespace std; int main() { int choice; char repeat; double MidTerm = 0; double FinalExam = 0; double Quiz1 = 0; double Quiz2 = 0; double MidTermGrade = 1, FinalExamGrade = 2, Quiz1Grade = 3, Quiz2Grade = 4,...

  • Fix my code, if I the song or the artist name is not on the vector,...

    Fix my code, if I the song or the artist name is not on the vector, I want to user re-enter the correct song or artist name in the list, so no bug found in the program #include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; class musicList{ private: vector<string> songName; vector<string> artistName; public: void addSong(string sName, string aName){ songName.push_back(sName); artistName.push_back(aName); } void deleteSongName(string sName){ vector<string>::iterator result = find(songName.begin(), songName.end(), sName); if (result == songName.end()){ cout << "The...

  • Hello, I am working on my final and I am stuck right near the end of...

    Hello, I am working on my final and I am stuck right near the end of the the program. I am making a Tic-Tac-Toe game and I can't seem to figure out how to make the program ask if you would like to play again, and keep the same names for the players that just played, keep track of the player that wins, and display the number of wins said player has, after accepting to keep playing. I am wanting...

  • Am I using the right cin statement to take in values for my array? If I...

    Am I using the right cin statement to take in values for my array? If I print them out it prints "0x61fea0" with the input 1 2 3 4 5 ///////////////////////////////// #include <iostream> using namespace std; const int ARRAY_LENGTH = 5; int main(){ int numbers[ARRAY_LENGTH]; int threshold; //@todo prompt user to enter array values cout << "Please input 5 numbers: " << endl; for(int i = 0; i < ARRAY_LENGTH; i++){ //@todo add cin statement to read in values for...

ADVERTISEMENT
Free Homework Help 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.
ADVERTISEMENT
ADVERTISEMENT