how to pass information from a array to a variable based on user input.
I am making a program and am trying to figure out how to let the user select a item from a menu then print out a bill based on the item the user chose. But i can assume that the user only can select 1 of each item. Here is the code. I will continue to work on it. I am still learning about arrays.
Code:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
struct menuItemType
{
string menuItem;
double menuPrice;
};
const int NUMBER_OF_ROWS = 8;
const int NUMBER_OF_COLUMNS = 2;
void showMenu(menuItemType menuList[NUMBER_OF_ROWS]);
void getData(menuItemType menuList[NUMBER_OF_ROWS]);
double printCheck(menuItemType menuList[NUMBER_OF_ROWS]);
int main()
{
menuItemType menuList[NUMBER_OF_ROWS];
getData(menuList);
showMenu(menuList);
printCheck(menuList);
}
void getData(menuItemType menuList[NUMBER_OF_ROWS])
{
ifstream inFile;
inFile.open("C:\\Users\\Dylan\\Documents\\InfileTravischapter9Page629.txt");
for (int i = 0; i < 8; i++)
{
inFile >> menuList[i].menuItem
>> menuList[i].menuPrice;
}
}
void showMenu(menuItemType menuList[NUMBER_OF_ROWS])
{
menuItemType menuList;
getData(menuList);
int choice;
for(int i=0; i < 8; i++)
{
cout << menuList->menuPrice << endl;
}
cout << "What would you like to eat, you can have up to one of each item on the menu" << endl;
cout << "Press the following keys to select your items" << endl;
cout << "1 = Plain\n2 = Bacon and Egg\n 3 = Muffin\n 4 = French Toast\n 5 = Fruit Basket \n 6 = Cereal \n 7 = Coffee \n 8 = Tea" << endl;
cin >> choice;
}
double printCheck()