Can anyone tell me why line 140-144 of this program does not do what it is supposed to do.

Here is the output and you can see it is all blank? What am I missing?

hit any letter keys to add items to the order and then = to stop "ordering" food.

Streit's Burger Stop


Date: Nov 17,2009 Time: 12:16:50

......................................... 0.00
......................................... 0.00
......................................... 0.00
----------------------------------------------
Amount 0.00
6% Sales Tax 0.00
==============================================
Total
==============================================
Amount tendered 14.25


Change 14.25

THANK YOU FOR VISITING
Streit's Burger Stop

/* Program Name:Register.cpp

   Description: program simulates a register at a fast food restaurant

   Name:Scott Streit			Class No.: 4467
   Date:11/14/09			  	VisualC++
*/
//********************************** Includes
#include <cfloat>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cctype>
#include <iomanip>
#include <cmath>
#include <fstream>
#include <string>
#include <ctime>
#include <conio.h>
#include <windows.h>
#include <sstream>

#define cls system("cls")
#define frz system("pause");
#define yl  system("color 0e");

using namespace std;

//********************************** Type definitions
struct cashregister
{
	string key;
	string item;
	double price;
};//end structure

ifstream inputfile ("i:\\c++\\food.txt");
ofstream print ("i:\\c++\\register.txt");
//********************************** Function Prototypes
void initalize(cashregister menu[26], cashregister order[26],double &amount, double &tax, double &total, int &count, double &cash, double &change);
void checkdatafile();
void getdata(cashregister menu[26]);
void takeorder(cashregister menu[26], cashregister order[26], int &count);
void math(cashregister order[26], int &count,double &amount, double &tax, double &total, double &cash, double &change);
void displayorder(cashregister order[26], int &count, double &amount, double &tax, double &total, double &cash, double &change);
//********************************** Main Function


int main()
{
	time_t t;
	time(&t);
	yl;
	cls;
	cashregister menu[26];
	cashregister order[26];
	double amount=0;
	double tax=0;
	double total=0;
	double cash=0;
	double change=0;
	int count=0;

	//function calls
	initalize(menu, order, amount, tax, total, count, cash, change);
	checkdatafile();
	getdata(menu);
	takeorder(menu, order, count);
	math(order, count, amount, tax, total,cash, change);
	displayorder(order, count, amount, tax, total, cash, change);
	

       
	frz;
	return 0;
} // end of main function

//********************************** Function Definitions
void initalize(cashregister menu[26], cashregister order[26], double &amount, double &tax, double &total, int &count, double &cash, double &change)
{
  	int i;
	for(i=0; i<26; i++)
	{
		menu[i].key="";
		menu[i].item="";
		menu[i].price=0.0;
		order[i].key="";
		order[i].item="";
		order[i].price=0.0;
	}
	total=0.0;
	tax=0.0;
	count=0;
	cash=0;
	change=0;

}// end initialize
void checkdatafile()
{
	if(!inputfile)
	{
		cout<<"Error opening data file\n";
		frz;
		exit(1);
	}//end if
}//end checkdatafile
void getdata(cashregister menu[26])
{
	for(int i=0; i<26; i++)
	{
		getline(inputfile, menu[i].key);
		getline(inputfile, menu[i].item);
		inputfile>>menu[i].price;		
		inputfile.ignore(80,'\n');
	} // end for
	inputfile.close();
	
	
	
	//for (int i=0;i<26;i++)
	//{
	//	cout<<menu[i].key<<"\t"<<menu[i].item<<"\t"<<menu[i].price<<"\n";
	//}//end temporary display item
} // getdata
void takeorder(cashregister menu[26], cashregister order[26], int &count)
{
	string phrase;
	string keystroke;
	phrase="Welcome to Streit's Burger Stop";
	cout<<setw((phrase.length()/2)+40)<<phrase<<"\n";
	cout<<"\nPlease begin entering your order.\n";

	while ((keystroke=getch())!="=")
	{
		//keystroke=toupper(keystroke);
		count++;
		for (int i=0;i<26;i++)
			if (keystroke==menu[i].key)
			{
				menu[i].key=order[count].key;
				menu[i].item=order[count].item;
				menu[i].price=order[count].price;
			}//end if
	}//end while

	for (int i=0;i<count;i++)
	{
		cout<<order[i].item<<"\n";
		cout<<order[i].price<<"\n";
	}

}//end takeorder
void math(cashregister order[26], int &count, double &amount, double &tax, double &total, double &cash, double &change)
{
	for (int i=0;i<count;i++)
	{
		amount +=order[i].price;
	}//end total calculation
	tax=amount*.06;
	total=amount+tax;
	cout<<fixed<<showpoint<<setprecision(2);
	print<<fixed<<showpoint<<setprecision(2);
	
	cout<<"Total due: "<<total<<"\nPlease enter amount tendered: ";
	cin>>cash;
	while (cash<total)
	{
		cout<<"Amount insufficient. Please re-enter amount tendered: ";
		cin>>cash;
	}//end while
	change=cash-total;
	cout<<"You change is: "<<change<<endl;

	frz;
}//end math
void displayorder(cashregister order[26], int &count, double &amount, double &tax, double &total, double &cash, double &change)
{
	system("cls");
	time_t t;
	time(&t);
	string phrase;
	string both, date, time;
	phrase="Streit's Burger Stop\n\n";
	cout<<setw((phrase.length()/2)+23)<<phrase<<"\n";
	print<<setw((phrase.length()/2)+23)<<phrase<<"\n";
	both=ctime(&t);
	date=both.substr(4,6)+","+both.substr(20,4);
	time=both.substr(11,8);
	cout<<"Date: "<<date<<"\t\tTime: "<<time<<endl<<endl;
	print<<"Date: "<<date<<"\t\tTime: "<<time<<endl<<endl;
	for (int i=0;i<count;i++)
	{
		for (int j=order[i].item.length();j<=40;j++)
           order[i].item+=".";
		cout<<order[i].item<<" "<<order[i].price<<"\n";
		print<<order[i].item<<" "<<order[i].price<<"\n";
	}//end add line of dots to name
	for (int i=0;i<46;i++)
	{
		cout<<"-";
		print<<"-";
	}//end dash line
	cout<<"\nAmount\t\t\t\t\t  "<<amount<<endl;
	print<<"\nAmount\t\t\t\t\t  "<<amount<<endl;
	cout<<"6% Sales Tax\t\t\t\t  "<<tax<<endl;
	print<<"6% Sales Tax\t\t\t\t  "<<tax<<endl;
	for (int i=0;i<46;i++)
	{
		cout<<"=";
		print<<"=";
	}//end dash line
	cout<<"\nTotal\t\t\t\t\t  "<<total<<endl;
	print<<"\nTotal\t\t\t\t\t  "<<endl;
	for (int i=0;i<46;i++) 
	{
		cout<<"=";
		print<<"=";
	}//end dash line
	cout<<"\nAmount tendered\t\t\t\t "<<cash<<"\n\n\n";
	print<<"\nAmount tendered\t\t\t\t "<<cash<<"\n\n\n";
	cout<<"Change\t\t\t\t\t "<<change<<"\n\n";
	print<<"Change\t\t\t\t\t "<<change<<"\n\n";
	phrase="THANK YOU FOR VISITING";
	cout<<setw((phrase.length()/2)+23)<<phrase<<"\n";
	print<<setw((phrase.length()/2)+23)<<phrase<<"\n";
	phrase="Streit's Burger Stop";
	cout<<setw((phrase.length()/2)+23)<<phrase<<"\n";
	print<<setw((phrase.length()/2)+23)<<phrase<<"\n";
	

}//end display order

There are a few issues in here that could cause your output to be incorrect.

First, your keystroke input is generally going to be a lowercase letter, but your data file only uses capital letters. You'll have to error check the input and make the character an uppercase letter. The following is a quick & dirty way to make that happen w/out error checking.

keystroke = *keystroke.c_str() - 32

Second, your assignment is backwards on lines 140-142.

Third, I would recommend only incrementing the count variable when valid input is received, rather than every time it enters that function.

Hope that points you in the right direction. Good luck.

There are a few issues in here that could cause your output to be incorrect.

First, your keystroke input is generally going to be a lowercase letter, but your data file only uses capital letters. You'll have to error check the input and make the character an uppercase letter. The following is a quick & dirty way to make that happen w/out error checking.

keystroke = *keystroke.c_str() - 32

Second, your assignment is backwards on lines 140-142.

Third, I would recommend only incrementing the count variable when valid input is received, rather than every time it enters that function.

Hope that points you in the right direction. Good luck.

you are the MAN. So easy to overlook something like that.

Thank you.

What's more you should increment count variable at the end of the while loop, not at the beginning (before assignment).

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.