Good day:
My infile contains the following:

U
Apple Pie
1.29
A
Bacon Burger
3.45
V
Burrito
2.09
S
Cheeseburger, Double
3.59
W
Cheeseburger, Regular
2.95
Y
Chicken Nuggets
1.87
H
Chicken Sandwich
3.33
C
Chili, Bowl
2.12
X
Chili Dog
2.29
N
Chocolate Milk
0.98
D
Coffee
1.09
R
Fries, Large
1.89
F
Fries, Small
1.19
Q
Hamburger
2.45
Z
Hot Dog
1.99
T
Onion Rings, Large
2.59
G
Onion Rings, Small
1.57
J
Peach Pie
1.29
I
Potato, Baked
1.47
P
Salad, Regular
3.69
K
Salad, Side
1.95
M
Shake, Large
1.98
B
Shake, Small
1.49
O
Soft Drink, Large
1.69
L
Soft Drink, Regular
1.49
E
Soft Drink, Small
1.06

The assignment:
You are familiar with computer-driven systems used by cashiers in fast food restaurants. In this
project, you will plan and write a program that will simulate such a point-of-sale device. Here's how
it will work.
When a customer orders, the cashier presses a key for each item ordered (WITHOUT PRESSING
<ENTER>). If more than one of the same item is ordered, the key is pressed an appropriate
number of times. As each key is pressed, the name of the item and its price are displayed on the
next available line on the monitor. Typically, a customer might order a sandwich, then fries or
onion rings and finally, a drink or dessert.
After the customer finishes ordering, a key is pressed to indicate that the order is finished. The
computer at this point displays the amount of the bill, then a 6% sales tax and a total of the order
(amount plus tax). The customer gives the cashier money, the cashier enters the amount given
(tendered). The computer calculates and displays the amount of change that should be returned
to the customer. lf the amount of money tendered is insufficient to cover the total, the program
should alert the cashier to this fact and request re-entry of the tendered amount. The program will
then print the entire order and transaction to the printer so that the customer can have a receipt.
The letters, names and prices of the different menu items must be read in from a file named
"food.txt" and be stored in three parallel arrays and then accessed as needed.
The EQUAL KEY ( = ) will be used as the key to indicate that the order is finished. The items in
the disk file or the arrays must NOT be displayed as a menu on the screen. The following is an
alphabetical list of the food items offered for sales along with their respective key letters and
prices.

KEY                   ITEM                        PRICE                              
U                     Apple Pie                           1.29 
Q                    Hamburger                          2.45
A                    Bacon Burger                       3.45 
Z                     Hot Dog                              1.99
V                     Burrito                               2.09 
T                      Onion Rings, Large             2.59
S                  Cheeseburger, Double             3.59 
G                  Onion Rings, Small                 1.57
W                Cheeseburger, Regular            2.95 
J                    Peach Pie                             1.29
Y                 Chicken Nuggets                      1.87 
I                  Potato, Baked                         1.47
H                  Chicken Sandwich                   3.33 
P                  Salad, Regular                        3.69
C                    Chili, Bowl                            2.12 
K                     Salad, Side                          1.95
X                       Chili Dog                            2.29 
M                      Shake, Large                       1.98
N                      Chocolate Milk                     0.98 
B                     Shake, Small                        1.49
D                    Coffee                                    1.09 
O                    Soft Drink, Large                    1.89
R                     Fries, Large                            1.89 
L                     Soft Drink, Regular                  1 .49
F                        Fries, Small                          1.19 
E                      Soft Drink, Small                     1.06

On the reverse side is a sample receipt so that you can design your output accordingly. Naturally,
the name of your restaurant should reflect your LAST name and show some IMAGINATION and
ORIGINALITY.
The output is suppose to look like this(as an example):

Zandiago’s  Z-BURGER SHACK    
Date: Oct 25-07 Time: 18:31:26
Hamburger .............................. 2.45
Salad, Regular ......................... 3.69
Cheeseburger, Regular .................. 2.95
Soft Drink, Regular .................... 1.69
Soft Drink, Small ...................... 1.06
Potato, Baked .......................... 1.47
Fries, Large ........................... 2.59
Apple Pie .............................. 1.29
Onion Rings, Large ..................... 2.59
Chicken Nuggets ........................ 1.87
Amount 20.95
6% Sales Tax 1.26
Total 22.21
Amount Tendered 25.00
Change 2.79
THANK YOU FOR VISITING
Zandiago’s  ZBURGER SHACK

So far:

#include <iomanip>
#include <cmath>
#include <fstream>
#include<string>
#include<iostream>
#include<conio>


    float Tax;
    float subtotal;
    float total;
    float price;

    using namespace std;

/*functions protypes*/

void enterItemPrice();
void subTotal();
void calculatetax();
void totalprice();
void output();

int main()
{
    cout<<"Zandiago's Z-Burger Shack"<<endl;
    
    enterItemPrice();
    subTotal();
    calculatetax();
    totalprice(total);
    output();


    return 0;     
}

void enterItemPrice()
{
while ((targetletter = getch())!='=')
    
}     

void subTotal()
{
    
    return subtotal;
    
}

void calculatetax()
{
    Tax = subtotal * TaxRate;
}     

void totalprice()
{
    total= Tax + subtotal;
}

void output()
{
    cout<<item<<endl;
    cout<<"------------------------------------------"<<endl;
    cout<<total<<price<<endl;
    cout<<"6 % Sales Tax"<<Tax<<endl;
    cout"============================================"<<endl;
    cout"Total"<<subtotal<<endl;
    cout<<"Amount tendered"<<cashin<<endl;
    cout<<"Change"<<(cashin-subtotal)<<endl;
    cout<<"Thank you for visiting"'\n';
    cout<<"Zandiago's Z-Burger Shack"<<endl;
}

Questions:
1. Considering the nature of the infile, how do i go above storing data into the three paralel arrays and what exactly will i be storing in the array from the infile?
2. I guess that once the data is in the array, then when i select a food type, it will automatically come up on the screen until the termination key (in this case '=') is pressed?
Any additional pointers are appreciated.

Sequentially read in a char, a string, and a double. The char goes in one array, the string in another and the double in a third. The index of the array and the array name is the key to accessing any one of items in any array. So when the user inputs a V you search the char array until you find V. Then index is then used in the string array to find the name and in the double array to find the cost. Then it's a matter of setting up control structures and counters to allow the user to select as many items in any order they want. It appears that the receipt isn't printed on the run, but only after the = sign has been entered, so you will probably need to keep track of all selections in a separate char array/vector/list and loop through the container once the input is completed.

Thx for your input. So i guess something like this:

myarray[letter][item][cost];

If you look at my infile (as show before), how do i get the data from each individual line to be stored in the array?

Nah, it's something like this:
char itemID[]
string itemName[]
double itemCost[]

If the file to be read in is exactly the one posted then you know the total number of items to be read in so you know the exact size the arrays need to be.

Since the information that goes in each array comes from the file, you will need to oopen the file for reading. Since each item is listed on a separate line you can use a sequence of input statements. In this case you might use a >> followed by a getline() followed by a >>. If you do that however, be sure you ignore the newline left in the input buffer by the >> called just before the call to getline() or you'll get off track.

When a customer orders, the cashier presses a key for each item ordered (WITHOUT PRESSING
<ENTER>). If more than one of the same item is ordered, the key is pressed an appropriate
number of times. As each key is pressed, the name of the item and its price are displayed on the
next available line on the monitor....

Ouch!!! Considering Standard CPP cannot do this, your instuctor is teaching techniques that cannot be used normally in the industry. I don't like this at all. :icon_evil:

If you look at my infile (as show before), how do i get the data from each individual line to be stored in the array?

Read the line and break it up into it's 3 parts. To learn the most, test the line character by character and process each section accordingly.

Have you considered using a struct or class for each item on the menu?

Thx for the input. Salem, we haven't yet done struct/class, but i'll read up on it to see how i could do it. Let me make some more modifications to see how far we can go. Thx again for the assistance.

Good day:

#include <iomanip>
#include <cmath>
#include <fstream>
#include<string>
#include<iostream>
#include<conio.h>


using namespace std;


int main()
{
	
	ifstream inFile;
	ofstream outFile;

	inFile.open ("food.txt");
	outFile.open ("foodout");
		
	char letter[30];
	string item[30];
	double cost[30];

	const double taxrate = 0.06;
	double mealprice, tax, amount_tendered,change, total; 

	inFile>>letter[30];
	inFile>>item[30];
	inFile>>cost[30];

	cout<<letter<<item<<cost<<endl;

	//calculate tax and total price
	tax = (mealprice * taxrate);
	subtotal = mealprice + tax;

	//Display receipt
	cout<<endl;
	cout<<"Zandiago’s  Z-BURGER SHACK"<<endl;
	cout<<"Amount"<<mealprice<<endl;
	cout<<"6 % Sales Tax"<<tax<<endl;
	cout"============================================"<<endl;
	cout"Total"<<total<<endl;
	cout<<"Amount tendered"<<amount_tendered<<endl;
	cout<<"Change"<<(amount_tendered-total)<<endl;
	cout<<"Thank you for visiting"'\n';
	cout<<"Zandiago's Z-Burger Shack"<<endl;



	return 0;
}

How can i get the info from the infile(one data stored on top of the other) to be stored into the arrays and i have? Thx for your input.

Whenever you want to do the same task over again think of a loop.

Remember that if you declare an array like this:

int x[10];

then accessing an element with any index over 9, like x[10], or under zero, like x[-4], is out of bounds and likely cause problems in one shape or form. This is much less a problem with vectors, which is one reason why they can be easier to use.

How can i get the info from the infile(one data stored on top of the other) to be stored into the arrays and i have? Thx for your input.

You're close.

Defining char letter[30]; gives you letter[0] thru letter[29], therefore this code

inFile>>letter[30];
	inFile>>item[30];
	inFile>>cost[30];

reads the first 3 values into the array entries after the array definitions.

You need to put the inputs into a loop, using the loop index from 0 to 29 as the index into the variables.

Also, consider using whitespace for readability. For example

//Display receipt
	cout << endl;
	cout << "Zandiago’s  Z-BURGER SHACK" << endl;
	cout << "Amount" << mealprice << endl;
	cout << "6 % Sales Tax" << tax << endl;
	cout << "============================================" << endl;
	cout << "Total" << total << endl;
	cout << "Amount tendered" << amount_tendered << endl;
	cout << "Change" << (amount_tendered-total) << endl;
	cout << "Thank you for visiting"'\n';
	cout << "Zandiago's Z-Burger Shack" << endl;

Lerner....some some of the posts that i read, i see you're a strong beleiver of using vectors. I had tried to compile a program using DEV C++, in which i used vectors and it didn't compile...but the same program worked in microsoft's visual c++...unfortunately, my professor uses DEV C++ to check all assignments. Thx though for your input & also to you WaltP.

where do i go from here?

If you're having more problems, ask a question.
If this project is done, start a new one.

Given limitations of using standard C++ here's an outline:

ifstream inFile("food.txt");	
 
//parallel arrays to hold menu information contained in input file	
char letter[30];	
string item[30];	
double cost[30]; 

//use a loop to populate arrays
for(int i = 0; i < 30; ++i)
{
   inFile >> letter[i];

   //clear newline from input buffer before calling getline()--this isn't the most robust way to do this, but it's good enough for now
   inFile.ignore();

   //item string will have spaces so use getline  
   getline(inFile, item[i]);
	
   inFile >> cost[i]; 	

   //debugging line
   cout << letter[i]  << ' ' <<  item[i] << ' ' << cost[i] << endl;
}

char selections[100];  //array to hold customer selections, up to max 99 items per receipt

//instructions to enter menu selections 
cout << "enter selections, on letter per selection" << endl;
cout << "press the = key followed by the enter key to stop entry and print bill" << endl;
 
cin.getline(selections, 99, '=');      
 
int numSelections = strlen(selections);
double costOfSelections = 0.0;
int index;

//use selections and parallel arrays to determine items selected and cost of each selection and print information on receipt

for(int i = 0; i < numSelections; ++i)
{
   //compare each element (aka letter[j]) in the letter array withe each element (aka selections[i]) in selections using a loop.   
    for(int j =0; j < 30; ++j)
        If selections[i] equals letter[j]
            then assign i to index

   //once index for current selection determined use it to print item and cost on receipt

   //add cost of current selection to costOfSelections

  //start new line
}

//Then do whatever you need to do:
  //calculate tax and print it on receipt
  // add tax to costOfSelections to determine amount due and print amount due on receipt
  //enter amount tendered
  //determine change, insufficient funds, whatever
  //etc

Good day. Here is my revised code:

#include <iomanip>
#include <cmath>
#include <fstream>
#include<string>
#include<iostream>
#include<conio.h>


using namespace std;


int main()
{
    
    ifstream inFile;
    ofstream outFile;

    inFile.open ("food.txt");
    outFile.open ("foodout");
        
    char letter[30];    
    string item[30];    
    double cost[30]; 
    double taxrate = 0.06;
    double costOfselections=0;

    for(int i = 0; i < 30; ++i)
    {
     inFile >> letter[i];
    

    inFile.ignore();

   getline(inFile, item[i]);
    
   inFile >> cost[i];     
    }

    char selections[100];

    //instructions to enter menu selections 
    cout << "enter selections, on letter per selection" << endl;
    cout << "press the = key followed by the enter key to stop entry and print bill" << endl;

    cin.getline(selections, 99, '=');      

    int numSelections = strlen(selections);
    double costOfSelections = 0.0;
    int index;

    for(int i = 0; i < numSelections; ++i)
    {
     
    for(int j =0; j < 30; ++j)
        if (i = j)
        i = index;
    }

    //calculate tax and total price
    double tax = (costOfselections * taxrate);
    double subtotal = (costOfselections + tax);
    double amount_tendered;
    cin>>amount_tendered;

    if (amount_tendered<subtotal)
    {
        cout<<"You need more funds!"<<endl;
    }
    else
    {

    //Display receipt
    cout<<endl;
    cout<<"Zandiago’s  Z-BURGER SHACK"<<endl;
    cout<<"Amount"<<cost<<endl;
    cout<<"6 % Sales Tax"<<tax<<endl;
    cout<<"============================================"<<endl;
    cout<<"Total"<<subtotal<<endl;
    cout<<"Amount tendered"<<amount_tendered<<endl;
    cout<<"Change"<<(amount_tendered-subtotal)<<endl;
    cout<<"Thank you for visiting"<<endl;
    cout<<"Zandiago's Z-Burger Shack"<<endl;
    }



    return 0;
}

I have a few questions. I wanted tge program, each time a customer chooses an item, for it to be displayed as he/she chooses. It's also telling me that index is undeclared. I wanted the output to look something like:

Example of output

Zandiago’s  Z-BURGER SHACK    
Date: Oct 25-07 Time: 18:31:26
Hamburger .............................. 2.45
Salad, Regular ......................... 3.69
Cheeseburger, Regular .................. 2.95
Soft Drink, Regular .................... 1.69
Soft Drink, Small ...................... 1.06
Potato, Baked .......................... 1.47
Fries, Large ........................... 2.59
Apple Pie .............................. 1.29
Onion Rings, Large ..................... 2.59
Chicken Nuggets ........................ 1.87
Amount         20.95    
6% Sales Tax      1.26
Total       22.21
Amount Tendered    25.00
Change     2.79
THANK YOU FOR VISITING
Zandiago’s  ZBURGER SHACK

Good day.

G'day, mate!

I have a few questions. I wanted tge program, each time a customer chooses an item, for it to be displayed as he/she chooses. It's also telling me that index is undeclared.

Please be a little clearer. Your first question has an obvious answer, therefore I must be interpreting it wrong. The second doesn't make sense unless it's a compile error. And you know enough to post the what and where the error is if that's what the problem is. So that can't be it, either.

And haven't we mentioned formatting your code at least once? Or was that someone else?

The standard for keyboard input in C++ is to have the input displayed (echoed) to the screen as a key is pressed, and held in an input buffer until the enter key is pressed. The enter key is the trigger to transfer the information in the input buffer into the variable(s) indicated by the input method called on the input stream object used in the code.

This is somewhat limiting. For example, in games or other interactive environments, you don't want to have to hit the arrow key followed by the enter key everytime you want the item on the screen to change orientation, etc. It is my understanding, limited though it is, that the way around this is to use non-standard functions that don't buffer the input and don't echo the input to the scrren. The non-buffered, non-echoing input function for char input is getch() contained in conio.h (which is a nonstandard header file not available in all compilers, in which case you may need to import it if you want to use it) or possibly _getch(), cscanf() or cgets() (on some MS Visual C++ compilers from what I can find information on).

If this nonstandard behavior is desired, then you could add conio.h to the list of header files (if it's available to your compiler already) and rather than an array of char called selections just declare a single char for a single selection

char selection;

on line 39 of post #14.

Instructions to enter menu selections would be altered a little bit to avoid using the enter key:

cout << "enter selections, on letter per selection" << endl;
cout << "press the = key followed to stop entering selections" << endl;

and I'd use a loop to enter selectios, display selections at desired location and accumulate costOfSelections for further use later in program

do
{
   selection = getch();  //here's where the keyboard input is
  
    //if selection != '=',  then use current selection to look up the index of selection in the letter array,  
    for(int index = 0; index < 30;  ++index)
    {
        if(selection == letter[index])
        {
           break
         }
      }

       //and then use index of current selection to display the information you want regarding name and cost of current selection like this 
       cout << cost[index];

      //and add cost of current selection to costOfSelections before getting next selection
    
}while(selection != '=');

This sequence would essentially replace lines 45 through 57 of post #14 which was how I would come as close to this process as I could using standard functionality of C++. Of course you're going to have to tweak this stuff a bit to do everything you want and you may need to change variable names to conform to the variable names you're using, etc, but I shouldn't be writing the finished product for you anyway.

How did you identify the index and can you please post the final code on here I'm very interested in this program

commented: Think he still has it from almost 3.5 years ago? -1

Since this is school work, and the thread is over 3 years old, its not likely that the op will post the final program. You will just have to write it yourself.

Im trying it but its not working! why?

Start a new thread and post the code that you have and the problem it is having.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.