Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Help fixing appliction bugs

Posted on 2004-09-30
2
245 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

838 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