I can get the first program to come up, I understand that part. But where I am lost is how do I get the menu to come back up so you can pick another selection?
When I am done with all the functions I should have 5 different ones.
I know it is a loop, but I have no idea how to do the DO..
I attempted different loops and all I get is errors. Thought I had it was down to one error. But got one when linking..
so I took the do loop out completely ( mostly so I don't look like a fool for you guys)
If you can point me in the right direction I would be one happy camper!
CODE
#include <string>
#include <iostream>
#include <iomanip>
//#include (fstream>
using namespace std;
// declare my functions 1st
void main_menu(int &selection);
float program1();
//float program2();
//void exit();
// Global variables?
int selection;
int main() // beginning of main function
{// you must call your function here
main_menu(selection);
if (selection == 1)
{
program1();
}
else if(selection == 2)
{
cout <<"program";
}
else if(selection == 0)
{
return 0;
}
else
{
cout <<"Invaild entry" <<endl;
}
return 0;
}
void main_menu(int &selection)
{
cout << "*********************************************************" << endl;
cout << "************ MENU **************" << endl;
cout << "************ Please make a selection **************" << endl;
cout << "************ **************" << endl;
cout << "*********************************************************" << endl;
cout << "*********************************************************" << endl;
cout << setiosflags(ios::fixed);
cout << " Option "<< setw(25) << "Description" <<endl;
cout <<" _______________________________________________________" <<endl;
cout <<"| |" <<endl;
cout <<"| |" <<endl;
cout <<"| 1. Calculate sales tax on items |" <<endl;
cout <<"| |" <<endl;
cout <<"| 2. Create a Customer contact card |" <<endl;
cout <<"| |" <<endl;
cout <<"| 3. Balance a checkbook |" <<endl;
cout <<"| |" <<endl;
cout <<"| 4. Calculate sales item from file |" <<endl;
cout <<"| |" <<endl;
cout <<"| 5. Trip mileage Report |" <<endl;
cout <<"| |" <<endl;
cout <<"| 6. Exit |" <<endl;
cout <<"| |" <<endl;
cout <<"|_______________________________________________________|" <<endl;
cout <<"**********************************************************"<<endl;
cout <<"Please make your selection: ";
cin >> selection;
}
float program1()
{
// define var's
float total_sales = 0;
float sales_tax;
float grand_total;
float price;
int num_items;
int counter = 1;
char answer;
int x = 1;
do
{
system("cls");
counter = 1;
total_sales= 0;
// input
cout <<"How many sale items do you have? : ";
cin >> num_items;
// while statement
while(counter <= num_items)
{
cout <<"Enter the value of sales item" << counter << " : $";
cin >> price;
counter = counter + 1;
total_sales = total_sales + price;
}
// output
sales_tax = total_sales * .06;
grand_total = sales_tax + total_sales;
cout << endl;
cout << "********************************************" << endl;
cout << "******** S A L E S R E C E I P T ********" << endl;
cout << "********************************************" << endl;
cout << "** **" << endl;
cout << "** **" << endl;
cout << "** **" << endl;
cout << "** **" << endl;
cout << setiosflags(ios::fixed) << setprecision(2);
cout << "** Total Sales $" << setw(9) << total_sales << " **" << endl;
cout << "** Sales tax $" << setw(9) << total_sales * .06 << " **" << endl;
cout << "** ----------- **" << endl;
cout << "** Grand Total $" << setw(9) << grand_total << " **" << endl;
cout << "** **" << endl;
cout << "** **" << endl;
cout << "********************************************" << endl;
cout << endl;
cout << "Would you like for this program to run again?" << endl;
cout << "Please enter y or n."<< endl;
cin >> answer;
}
while (answer == 'Y' || answer == 'y');
return grand_total;
}
edit: added [code] tags ~ jayman9