AH! THANK YOU!!! That's an interesting trick if you aren't confident in your ability to keep track of dynamic arrays. It's definatly worth learning how to use "std::vector" though.
i am suposed to use dynamic array, but truth be told i have no idea how.
somehow i am supposed to get the 8 which makes an array size 8 like the menu choices.
I am able to open the file
but i do not know how to get the different lines and different data types(the price in this case)
and how to display it as a Regular Menu like the example up.
- If you want your price displayed on the same line as your item you need to modify Line 12.
EDIT: - This cannot be called a Dynamic Array and your teacher should be made to to sit in a corner with their nose to the wall for saying such rot. But you need to make menuList into an array of strings if this is what you plan on accomplishing.
That's an interesting trick if you aren't confident in your ability to keep track of dynamic arrays.
It also makes memory allocation more efficient. If you know how much data there is you can reserve enough space ahead of time instead of possibly having to reallocate several times.
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
usingnamespace std;
constdouble taxRate = 0.05;
struct menuItemType
{
string menuItem;
double menuPrice;
};
void openFile();
void showMenu( menuItemType mList[], int listSize);
void getData();
void makeSelection();//loads the customers selection into an orderList[]
int main()
{
ifstream inFile;
string menuList;
menyItemType *menuList;
int *orderList;// this is supposed to be an array
int numOfItems;// this will be 8 i assume from the 8 in the file.txt
inFile.open("menu.txt");
if (!inFile.is_open())
cout << "Did not open" << endl;
getline(inFile, numOfItems)
inFile << numOfItems;//i want to get the 8 from menu
menuList = new menuItemType [numOfItems];
orderList = newint [numOfItems];
}
- Double check line 28. There are too things rong there. <- My Attempt At Being Subtle
- "menuList" still isn't an array.
- If Line 34, then you should do something to prevent the rest of the code from executing. A simple thing would be to return from the program.
- Line 37 is missing something *HINT*-> ';' <-*HINT*
- You need a loop to read through the items in the file.
- You never set the value for numOfItems. There are a number of ways to do this but the simplist way would be to grab the first entry in the file, cast it as an 'int' and assign that to numOfItems.