Solved

Help fixing appliction bugs

Posted on 2004-09-30
2
239 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
ID: 12189324
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
ID: 12195678
use scanf() or getline()
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
basic hardware to learn oop advanced design patterns 3 96
Unresolved External Symbols 3 85
Unable to start eclipse ? 17 142
Copy output image from TWindowsMediaPlayer 6 41
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

803 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