Find the answer to your Linux question:
Results 1 to 3 of 3
hey guys, writing something for class here, the basic idea is, i have an input file. looks like so Line 1: account number - an 8 character string line 2: ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2005
    Posts
    15

    nested if question.


    hey guys, writing something for class here, the basic idea is, i have an input file. looks like so

    Line 1: account number - an 8 character string
    line 2: customer name - a 20 character string
    line 3: account type code - character where r = regular, s= senior citizen , c=commercial.
    number of checks processed - integer
    minimum balance that month - double

    12-132-0
    Billy Bobson
    R 25 130.00

    and etc. there's 16 people.
    so i gotta take the input and spit out an output. here's my code, getting an error on the beginning of the first if statement.... the other ones aren't filled in yet but you get the idea... what could i be doing wrong?


    Code:
    #include <cstdlib>
    #include <iostream>
    #include <fstream>
    #include <iomanip>
    #include <string>
    
    using namespace std;
    
    
    
    int main()
    {
        
        // Making Variables for my program //
        
    ifstream      Input;                   
    ofstream      Output;
    char          FName[81];
    char          accountnumber[11];
    char          cust_name[22];    
    char          account_type[3];
    double        min_balance;
    int           checks_processed;
    double        service_charge;
    int           cust_count;
    int           sum_regular_accounts;
    int           sum_senior_accounts;
    int           sum_commercial_accounts;
    double        total_service_charges_regular;
    double        total_service_charges_senior;
    double        total_service_charges_commercial;
    char          cust_output[22];
    int           checks_processed_output;
    double        service_charge_output;
    double        min_balance_output;
    
    
    
    //////////////////////////////////////////////////////////////
    // setting up the connections to the input and output file. //
    //////////////////////////////////////////////////////////////
     
        
    cout         << "Where is the Input file jackass? ";
    cin.getline (FName,81);
    Input.open  (FName);
    
    cout         << "Where do you want the output? ";
    cin.getline (FName,81);
    Input.open  (FName);
    
    /////////////////////////////////////
    // Outputting the report headings //
    ////////////////////////////////////    
    
    Output << setw(1) << "Bob's Bank & Trust" << endl;
    Output << setw(1) << "Checking Account Service Charge Report" << endl << endl 
           << endl;
    Output << setw(1) << "Account" << setw(15) << "Account" << setw(6)  << "Minimum" 
           << setw(6) << "Checks"  << setw(6)  << "Service" << endl;
    Output << setw(1) << "Number"  << setw(7)  << "Name"    << setw(13) << "Type" 
           << setw(8) << "Balance" << setw(8)  << "Processed" << setw(4) << "Charge"
           << endl << endl;
    
    
    ////////////////////////////////////////////////////////////////////////////       
    // Now i'm ready to process the information first setup fixed output mode //
    ////////////////////////////////////////////////////////////////////////////
    
    Output << fixed << showpoint;
    
    checks_processed = cust_count = sum_regular_accounts 
    = sum_commercial_accounts = sum_senior_accounts = 0;
    
    total_service_charges_regular= total_service_charges_senior 
    = total_service_charges_commercial =  service_charge = 0;
    
    while (!Input.eof())  // While not at the end do the following //
    
    {
          
         Input.getline    (accountnumber,20);
         Input.getline    (cust_name,40);
         Input >> account_type >> checks_processed >> min_balance >> ws;
         cust_count++;
         
         
      
         
         
         
         min_balance_output == min_balance;
         checks_processed_output == checks_processed;
         service_charge_output == service_charge;
         
         
         if (account_type == 'R') {
         (min_balance_output < 100)
         service_charge_output ==  
                          
                           }
         else if (account_type == 'S') { 
              
              
              
              
              
                              ; }
         else {
              
              
              ;}
    
              
              
                                                     
         
         
         
         
         
         
         
         
         
         
         
         
         Input >> account_type >> min_balance >> checks_processed >> service_charge >> ws;
         
            
            
         
         
         
         
         
         
         
         }

  2. #2
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    I assume you refer to this:
    Code:
    if (account_type == 'R') {
         (min_balance_output < 100)
         service_charge_output ==  
                          
                           }
    This code makes no sense. You are likely getting the error because you are dangling the '==', that is, you are trying to compare service_charge_output to something, but don't actually say what you're comparing it to.

    That said, while I don't know what you want this to do, the (min_balance_output < 100) line currently does absolutely nothing. And there's no semicolon after it: another error.

  3. #3
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    I would think that that is what he meant by "the other ones aren't filled in yet but you get the idea...", though.

    However, there's an error with "account_type == 'R'" as well, because account_type is a "char [3]", while 'R' is just a char, and those types can, naturally, not be compared to each other. From the description of the problem, I can't really figure out why you've declared account_type as an array of three chars anyway, and it is my guess that you meant to declare it is just a single char (i.e. "char account_type;", not "char account_type[1];").

    Oh, and by the way: It probably helps if you open the output file properly:
    Quote Originally Posted by SlakAdykt
    Code:
    cout         << "Where is the Input file jackass? ";
    cin.getline (FName,81);
    Input.open  (FName);
    
    cout         << "Where do you want the output? ";
    cin.getline (FName,81);
    Input.open  (FName);

  4. $spacer_open
    $spacer_close

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •