View Single Post
Old 06-01-2006, 05:20 PM   #1 (permalink)
halloula
Registered User
 
Join Date: Jun 2006
Posts: 1
halloula is on a distinguished road
help with a program

i've done this program as part of my assigment but it won't compile and i got an error message saying a multipe definition of main plz have a look and try to help me solving this problem as i need it today
Code:
#include <iostream>
#include <string>
using namespace std;
int main() 
{
    string  id, 
            rest_of_the_line,
            name_and_address;

    // sub_header is a flag that indicates the sub header should be output
    bool sub_header = true;
    char gate;
    float total =0;
    const float amount_gate_A = 2.20;
    const float amount_gate_B = 2.80;
    const float amount_gate_C = 2.30;
    const float amount_gate_D = 3.80;
 
    while ( cin >> id >> gate )
    {
        getline(cin, rest_of_the_line);
        if ( gate == '@' )
        {
            if ( total > 0 )
            {
                // output the total
                cerr << "Total = " << total << endl;
            }
            // save the address as it will be overwritten in the next cin
            name_and_address = rest_of_the_line;
            // clear values of total and sub_header
            total = 0 ;
            sub_header = true;
        }
        else 
        {
            if ( sub_header )
            {
                cerr << " 1. Customer ID:"      << id               << endl;
                cerr << " 2. Name and Address:" << name_and_address << endl;
                cerr << " 3. Date        Time     Station    Amount"<< endl;
                sub_header = false;
            }


            // use substr to extract the date and time
           // The date is of length 11 and the rest is the time
            cerr << rest_of_the_line.substr(0,35 ) << "    " 
                 << rest_of_the_line.substr(36)  << "    " 
                 << gate << "        " ;

            if (gate == 'A')
            {
                cerr    << amount_gate_A;
                total   += amount_gate_A;
            }
            else if (gate == 'B')
            {
                cerr    << amount_gate_B;
                total   += amount_gate_B;
            }
            else if (gate == 'C')
            {
                cerr    << amount_gate_C;
                total   += amount_gate_C;
            }
            else if (gate == 'D')
            {
                cerr    << amount_gate_D;
                total   += amount_gate_D;
            }
            cerr << endl; 
        }
    }

    if ( total > 0 )
    {
        // output the total
        cerr << "Total = " << total << endl;
    }
    return 0;
}
halloula is offline   Reply With Quote