Glad I could help.
Just in case you wanted to see how I used it, this is the program I
was working on. Way beyond what the assignment required, but I have
always gone above and beyond.
Hopefully I am posting the code right. I read the FAQ portion of it
and hope I get it right. (I hate being the new guy!!) I cut out alot
of the white space to save room. This is not how I format everything
in the code.
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
// Declare Functions Here
int Display_Main_Menu (int);
void View_Totals (int, int, int, int, int);
int Check_Number (int);
void Wait ();
void Final_Data (int, int, int, int, int);
int main (int)
{
// Variables for various program functions
int day=1, prod_num, quantity_today=0;
int prod_1=0, prod_2=0, prod_3=0, prod_4=0, prod_5=0;
int main_selection, good_or_bad=1;
// Variables for continue statements
char cont='N';
char day_done = 'N';
while ( day <= 7 )
{
main_selection = Display_Main_Menu (day); // Calls Function
switch (main_selection)
{
case 1: // Input Data - While & Switch Loops
system ("cls"); // Clear Screen Command
cont = 'N'; // Must have to avoid infinite looping!!!
while (cont != 'Y' )
{
while ( good_or_bad != 0 )
{
cout << "\n\n\nEnter product number (1-5): ";
cin >> prod_num;
good_or_bad = Check_Number(prod_num);
} // Ends Inner While
good_or_bad = 1; // Reset it to avoid infinite looping!!!
cout << "Enter quantity sold on day " << day << ": ";
cin >> quantity_today;
cout << "\n\nYou sold " << quantity_today
<< " units of product " << prod_num << ".";
cout << "\nIs this correct (Y/N)?";
cin >> cont;
if ( cont == 'y' ) // Sets upper case letter
cont = 'Y';
} // Ends Middle While
switch (prod_num) // Add Quantity to Product Count
{
case 1:
prod_1 = prod_1 + quantity_today;
break;
case 2:
prod_2 = prod_2 + quantity_today;
break;
case 3:
prod_3 = prod_3 + quantity_today;
break;
case 4:
prod_4 = prod_4 + quantity_today;
break;
case 5:
prod_5 = prod_5 + quantity_today;
break;
} // Ends Inner Switch
break;
case 2: // User Selected "View Totals" - Call Function
View_Totals (prod_1, prod_2, prod_3, prod_4, prod_5);
break;
case 3: // User Wants to Advanced One Day
day++;
break;
case 4: // User Wants to End Input Session
day = 8;
break;
} // Ends Outer Switch
} // Ends While
// Display the final sales report from the data entered.
Final_Data (prod_1, prod_2, prod_3, prod_4, prod_5);
return 0;
} // Ends Main
/*This function will be called to display the main menu
for the user. The variable passed out of this function
tells the *main* what menu the user wishes to access.*/
int Display_Main_Menu (int daynum)
{
int selection;
system ("cls"); // Clear Screen Command
cout << "\n\n\nDay " << daynum;
cout << "\n\n*****MAIN MENU*****";
cout << "\n\n1: Enter Data";
cout << "\n2: View Current Totals";
cout << "\n3: Continue to day " << ( daynum + 1 );
cout << "\n4: End Input Session";
cout << "\n\n\nSelection: ";
cin >> selection;
return selection;
}
/*This function will be called to display the totals currently
on file from previous input. There is no value returned from
this function.*/
void View_Totals(int prod1,int prod2,int prod3,int prod4,int prod5)
{
system ("cls"); // Clear Screen Command
cout << "\n\n\nYour current totals are:" << endl;
cout << "\nProduct 1: " << prod1 << endl;
cout << "Product 2: " << prod2 << endl;
cout << "Product 3: " << prod3 << endl;
cout << "Product 4: " << prod4 << endl;
cout << "Product 5: " << prod5 << endl;
Wait(); // Creates a "Press Enter to continue" statement
}
/* This function determines whether the input product number is
correct. The value must be an integer between 1 and 5. If it is
valid, then a value of 0 is returned. If it is invalid, then a
value of 1 is returned.*/
int Check_Number(int prodnum)
{
int return_this;
switch (prodnum)
{
case 1:
case 2:
case 3:
case 4:
case 5:
return_this = 0;
break;
default:
return_this = 1;
break;
}
return return_this;
}
/* This function will use a string to create a pause until the user
hits the enter key. Any other characters entered will be ignored.*/
void Wait()
{
string response;
cout << "Press Enter to continue";
getline(cin, response);
}
/* This function will have the number of products passed into it.
From this data, it will determine the amount of each product sold
and total gross sales for the week. Then, it will display the data.*/
void Final_Data(int prod1,int prod2,int prod3,int prod4,int prod5)
{
double p1total, p2total, p3total, p4total, p5total, gross;
p1total = (prod1 * 2.98);
p2total = (prod2 * 4.50);
p3total = (prod3 * 9.98);
p4total = (prod4 * 4.49);
p5total = (prod5 * 6.87);
gross = (p1total + p2total + p3total + p4total + p5total);
system ("cls"); // Clear Screen
cout << "\n\n\nYour final sales report for this week is as follows:";
cout << "\n\nProduct Number\tAmount Sold\tTotal Income";
cout << "\n1\t\t" << prod1 << "\t\t" << "$" << p1total;
cout << "\n2\t\t" << prod2 << "\t\t" << "$" << p2total;
cout << "\n3\t\t" << prod3 << "\t\t" << "$" << p3total;
cout << "\n4\t\t" << prod4 << "\t\t" << "$" << p4total;
cout << "\n5\t\t" << prod5 << "\t\t" << "$" << p5total;
cout << "\n\nYour total gross sales for this week is $" << gross
<< "\n\n\n";
}