Hi![]()
How would I go about creating a menu to select 1 of two options
Here is the code
I am writing this for a school projectCode:#include <iostream> #include <fstream> using namespace std; int main(void) { char name[30]; char surname[30]; char id[30]; double hourrate; char hourratechar[30]; int numhour; char numhourchar[10]; char taxcredit[10]; float taxoutput; float basicpay; float overtime; float grosspay; float natins; float netpay; float totalmoney; cout <<"Please enter your name"<<endl; do { cin.getline(name,40); if(strlen(name) > 30) { cout<<"Error please enter sufficient characters"<<endl; } }while(strlen(name) > 30); cout <<"Please enter your surname"<<endl; do { cin.getline(surname,40); if(strlen(surname) > 30) { cout<<"Error please enter sufficient characters"<<endl; } }while(strlen(surname) > 30); cout <<"Please enter your ID"<<endl; do { cin.getline(id,15); if(strlen(id) > 5) { cout<<"Error please enter 5 numbers or less"<<endl; } }while(strlen(id) > 5); cout <<"Please enter your hourly rate"<<endl; cin.getline(hourratechar,30); hourrate= atof(hourratechar); do { cout <<"Please enter the number of hours you work"<<endl; cin.getline(numhourchar,30); numhour= atoi(numhourchar); if(numhour > 60) { cout<<"Error please enter 60 hours or less"<<endl; } }while(numhour > 60); if (numhour<=39) { basicpay=numhour*hourrate; } else { basicpay=39*hourrate; } if (overtime <= 39){ overtime = 0; } else if (overtime > 39) { overtime=numhour*hourrate*1.5; } grosspay=basicpay+overtime; cout <<"Please enter whether you get tax credits or not"<<endl; cin.getline(taxcredit,10); if (taxcredit[0]== 'y') { taxoutput=grosspay*0.22; } else { taxoutput=grosspay*0.20; } natins=grosspay*0.11; totalmoney=basicpay+grosspay+overtime+natins+netpay; netpay=grosspay-taxoutput-natins; ofstream outfile("result.txt"); cout <<""<<endl; cout <<"The employee entered the following information:"<<endl; cout <<""<<endl; cout <<"Their name" <<endl<<name; outfile << "--- Name ---"<<endl; outfile <<name; outfile <<endl; cout <<""<<endl; cout <<""<<endl; cout <<"Their surname" <<endl<<surname; outfile << "--- Surname ---"<<endl; outfile <<surname; outfile <<endl; cout <<""<<endl; cout <<""<<endl; cout <<"Their ID" <<endl<<id; outfile << "--- ID ---"<<endl; outfile <<id; outfile <<endl; cout <<""<<endl; cout <<""<<endl; cout <<"Their Hour Rate" <<endl<<hourrate; outfile << "--- Hourly Rate ---"<<endl; outfile <<hourrate; outfile <<endl; cout <<""<<endl; cout <<""<<endl; cout <<"Their Working Hours" <<endl<<numhour; outfile << "--- Number of Hours Worked ---"<<endl; outfile <<numhour; outfile <<endl; cout <<""<<endl; cout <<""<<endl; cout <<"Their Basic Pay" <<endl<<basicpay; outfile << "--- Basic Pay ---"<<endl; outfile <<basicpay; outfile <<endl; cout <<""<<endl; cout <<""<<endl; cout <<"Their Overtime Pay" <<endl<<overtime; outfile << "--- Overtime Pay ---"<<endl; outfile <<overtime; outfile <<endl; cout <<""<<endl; cout <<""<<endl; cout <<"Their Gross Pay" <<endl<<grosspay; outfile << "--- Gross Pay ---"<<endl; outfile <<grosspay; outfile <<endl; cout <<""<<endl; cout <<""<<endl; cout <<"Their Tax Credits" <<endl<<taxoutput; outfile << "--- Tax Credits ---"<<endl; outfile <<taxoutput; outfile <<endl; cout <<""<<endl; cout <<""<<endl; cout <<"National Insurance" <<endl<<natins; outfile << "--- National Insurance ---"<<endl; outfile <<natins; outfile <<endl; cout <<""<<endl; cout <<""<<endl; cout <<"Their Net Pay" <<endl<<natins; outfile << "--- Net Pay ---"<<endl; outfile <<netpay; outfile <<endl; cout <<""<<endl; cout <<""<<endl; cout <<"---- The Weekly Totals ----" <<endl; cout <<""<<endl; cout <<""<<endl; cout <<"Total Amount of Money" <<endl<<totalmoney; cout <<""<<endl; cout <<""<<endl; cout <<"Total Number of Hours" <<endl<<numhour; cout <<""<<endl; cout <<""<<endl; cout <<"Total Number of Overtime Hours" <<endl<<overtime; cout <<""<<endl; cout <<""<<endl; system("pause"); }
For option 1 I want to input all of the details and have it output them at the end so from the
down to theCode:cout <<"Please enter your name"<<endl; do
Code:cout <<"Total Number of Overtime Hours" <<endl<<overtime; cout <<""<<endl; cout <<""<<endl;
For option 2 I want to display a text file that the inputs have been saved into
Here's the code for it
I've tried creating a giant IF statement but no luckCode:int main () { string line; ifstream myfile ("result.txt"); if (myfile.is_open()) { while (! myfile.eof() ) { getline (myfile,line); cout << line << endl; } myfile.close(); } else cout << "Unable to open file";
Apologies if this is a lot of info to take in
Cheers for any help
Tom Evans



LinkBack URL
About LinkBacks



