Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Help fixing appliction bugs

Posted on 2004-09-30
2
Medium Priority
?
264 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
[X]
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
2 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 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.
Suggested Courses

722 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