I have an issue within my program where it sas the struct I have created is not initialized. Any suggestions?
The lab I am working on is
Write a program to help a local restaurant automate its breakfast billing system. The program should do the following:
Show the customer the different breakfast items offered by the restaurant.
Allow the customer to select more than one item from the menu.
Calculate and print the bill.
#include <iostream>
#include <string>
#include <fstream>
#include <ostream>
#include <istream>
#include <iomanip>
using namespace std;
//global Declarations
const int r = 8;
struct MenuItems
{
string menuItem;
double menuPrice;
int numOrdered;
}; //On this line I am getting an error for the variables being undefined
//Function prototypes
void getData(ifstream& menuFile, MenuItems menuArray[]);
void showMenu(MenuItems menuArray[], int r);
void printCheck(MenuItems menuArray[]);
int makeSelection(int number);
int main()
{
cout << "Timothy Cornwell -- Lab 9" << endl << endl;
//Variable declarations
char continueselection;
MenuItems menuArray[r];
ifstream menuFile;
int number;
double totalItems;
int choice;
double taxRate = 5/100;
double Tax;
double totalTax;
double totalBill;
//Program logic
cout << " Welcome to Johnny's Restaurant\n";
cout << " ---------Today's Menu---------\n";
showMenu(menuArray, r);
cout << endl;
getData(menuFile, menuArray);
for (int s = 0; s < r; s++)
{
menuArray[s].numOrdered = 0;
}
do
{
choice = makeSelection(number); // Also right here it says that the variable is uninitialized
while (choice < 0 || choice > r)
{
cout << "Invalid entry." << endl;
cout << endl;
choice = makeSelection(number);
}
totalItems = menuArray[number].numOrdered;
menuArray[number].numOrdered++;
cout << menuArray[number].numOrdered << setw(15) << menuArray[number].menuItem << endl;
cout << "Would you like to make a selection? Yes (Y/y) No (N/n): ";
cin >> continueselection;
} while (continueselection == 'Y' || continueselection == 'y');
cout << endl;
//calculating tax and printing check
totalTax = totalItems * taxRate;
Tax = (totalTax * 100 + .5) / 100;
totalBill = totalItems + Tax;
if (continueselection == 'N' || continueselection == 'n')
{
printCheck(menuArray);
}
//Closing program statements
system("pause");
return 0;
}
//Function Definitions
void getData(ifstream& menuFile, MenuItems menuArray[])
{
menuFile.open("menu.txt");
if (!menuFile)
cout << "Could not open menu file.";
else
{
string menuitem;
double cost;
for (int i = 0; i < 8; ++i)
{
getline(menuFile, menuitem);
menuFile >> cost;
menuFile.get();
menuArray[i].menuItem = menuitem;
menuArray[i].menuPrice = cost;
}
} menuFile.close();
}
void printCheck(MenuItems menuArray[])
{
int x = 0;
cout << "Welcome to Johnny's Restaurant\n";
for (x; x < r; x++)
{
if (menuArray[x].numOrdered > 0)
cout << menuArray[x].numOrdered << setw(15) << menuArray[x].menuItem << right <<
fixed << showpoint << setprecision(2) << "$" << menuArray[x].menuPrice << right << endl;
else
cout << "" << endl;
}
}
int makeSelection(int number)
{
number = 0;
cout << "Please choose an item on the menu: ";
cin >> number;
number = number - 1;
return number;
}
void showMenu(MenuItems menuArray[], int r)
{
for (int i = 0; i < 8; ++i)
{
cout << i + 1 << setw(15) << left << menuArray[i].menuItem << fixed << showpoint << setprecision(2) << "$" << menuArray[i].menuPrice << endl;
}
}