Solved

Help fixing appliction bugs

Posted on 2004-09-30
2
224 Views
Last Modified: 2010-04-01
Hello experts,

1. how do i make my console application wait for the user to press enter before an action.

2.I am  using the following code to print a bill, basically this is how it is suppose to work,

I have a data file wre i store customer details in the following format;-

ID   FIRSTNAME   LASTNAME    UNITS   TYPE
1      HARRY          JONES            33       IND

The thing is that often, the customer ID will occur a number of times. I need to be able to search for the first occurence of that customer ID and if the displayed bill is not correct, go to the next occurrence of that name.

here's the code I have so far, it does not work at all.


if (inTransaction.is_open())
{
      
      inTransaction.ignore (20, '\t');
      
      while (!inTransaction.eof())
      {

            inTransaction >> CustNo >> firstName >> lastName >> custCode >> Reading >> UnitsUsed >> AmountToPay;

            
            if (custID == CustNo)
            {
                  
                  cout << "\n\n" << CustNo << '\t' << firstName <<'\t' << lastName << '\t' << custCode << '\t' << Reading << '\t' << UnitsUsed << '\t' << AmountToPay << endl;
                  printBill << "n\n\t\t\t\t\tCUSTOMER BILL.\n\n";

                        printBill <<"\n\n Customer ID:" << CustNo;
                        printBill <<"\n\n Customer Name:" << firstName << " " << lastName;
                        printBill << "\n\n Expanded Rate:" << custCode;
                        printBill << "\n\n\n-----------------------------------------------------------------------";
                        printBill << "\n Previous Reading:\t\t\t\t\t"<< Reading;
                        printBill << "\n Gas Units Used:\t\t\t\t\t"  <<  UnitsUsed;
                        printBill << "\n-----------------------------------------------------------------------";

                        if (custCode == "BUS" || custCode == "IND")
                        {
                              printBill << "\n\nAmount To Pay: = \t\t\t\t\t  £"<<AmountToPay;
                              printBill << "\n-----------------------------------------------------------------------";
                        }
                        else
                        {
                              printBill << "\n\nAmount To Pay: = \t\t\t\t\t" << "****ERROR****";
                              printBill << "\n-----------------------------------------------------------------------";
                        }
                        
                        cout << "\n\nPrinting Customer Bill..!" << endl ;            

            }
            
            
      }
                  
}
else
{
      cout << "file not opened";

}
            inTransaction.close ();
                  printBill.close();
}
                  

0
Comment
Question by:claracruz
2 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
Comment Utility
Hi clara,

1. To make user wait for a key press, use getch() or maybe system("pause");

2. About your code, you can do something like this:

if (inTransaction.is_open())
{
    bool dontPrintHeader = false;    // Pay attention to the use of this variable

     inTransaction.ignore (20, '\t');
     
     while (!inTransaction.eof())
     {
          inTransaction >> CustNo >> firstName >> lastName >> custCode >> Reading >> UnitsUsed >> AmountToPay;
         
          if (custID == CustNo)
          {
               cout << "\n\n" << CustNo << '\t' << firstName <<'\t' << lastName << '\t' << custCode << '\t' << Reading << '\t' << UnitsUsed << '\t' << AmountToPay << endl;
               if (!dontPrintHeader) {
                    printBill << "n\n\t\t\t\t\tCUSTOMER BILL.\n\n";

                    printBill <<"\n\n Customer ID:" << CustNo;
                    printBill <<"\n\n Customer Name:" << firstName << " " << lastName;
                    printBill << "\n\n Expanded Rate:" << custCode;
                    printBill << "\n\n\n-----------------------------------------------------------------------";
                    printBill << "\n Previous Reading:\t\t\t\t\t"<< Reading;
                    printBill << "\n Gas Units Used:\t\t\t\t\t"  <<  UnitsUsed;
                    printBill << "\n-----------------------------------------------------------------------";
                    dontPrintHeader = true;
                }    

                    if (custCode == "BUS" || custCode == "IND")
                    {
                         printBill << "\n\nAmount To Pay: = \t\t\t\t\t  £"<<AmountToPay;
                         printBill << "\n-----------------------------------------------------------------------";
                    }
                    else
                    {
                         continue;   // Dont print "ERROR" and loop again until valid record is reached
                         //printBill << "\n\nAmount To Pay: = \t\t\t\t\t" << "****ERROR****";
                         //printBill << "\n-----------------------------------------------------------------------";
                    }
                   
                    cout << "\n\nPrinting Customer Bill..!" << endl ;          
          }
     }
}
else
{
     cout << "file not opened";

}
          inTransaction.close ();
               printBill.close();
}
0
 
LVL 9

Expert Comment

by:jhshukla
Comment Utility
use scanf() or getline()
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
maze travler 6 47
C++ assignment question 7 126
Dynamically allocate memory 9 46
C++ :Change value from  DisableCMD registry 4 8
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now