help in c++ program

This is a discussion on help in c++ program within the C++ Programming forums, part of the General Programming Boards category; sorry im beginner in c++ first semester doing it and i feel that's this assigment is too hard that's whay ...

  1. #16
    Registered User
    Join Date
    Apr 2006
    Posts
    22
    sorry im beginner in c++ first semester doing it and i feel that's this assigment is too hard that's whay im asking for help

  2. #17
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,696
    Quote Originally Posted by halloula
    i did correct that but i still got error message in line 51
    Not really. Just listen to your compiler:
    g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -Wall -pedantic

    main.cpp: In function `void readtolldetails(int&, int&, std::string&, std::string&, std::string&, int&, int&)':
    main.cpp:42: warning: statement has no effect

    main.cpp:51: error: argument of type `std::basic_string<char, std::char_traits<char>, std::allocator<char> > (std::basic_string<char, std::char_traits<char>, std::allocator<char> >:(unsigned int, unsigned int) const' does not match `char'
    main.cpp:52: error: argument of type `std::basic_string<char, std::char_traits<char>, std::allocator<char> > (std::basic_string<char, std::char_traits<char>, std::allocator<char> >:(unsigned int, unsigned int) const' does not match `char'
    main.cpp:50: warning: unused variable 'position'

    main.cpp:78:28: warning: multi-character character constant
    main.cpp: In function `void calculatetoll(std::string&, int, float&, float&, float&, float&, float&, double&)':
    main.cpp:78: warning: comparison is always false due to limited range of data type
    main.cpp:83:31: warning: multi-character character constant
    main.cpp:83: warning: comparison is always false due to limited range of data type

    main.cpp:88:31: warning: multi-character character constant
    main.cpp:88: warning: comparison is always false due to limited range of data type
    main.cpp:94: error: `totalI' undeclared (first use this function)
    main.cpp:94: error: (Each undeclared identifier is reported only once for each function it appears in.)

    main.cpp: In function `int main()':
    main.cpp:129: error: `station' undeclared (first use this function)
    main.cpp:129: error: `totalA' undeclared (first use this function)
    main.cpp:129: error: `totalB' undeclared (first use this function)
    main.cpp:129: error: `totalC' undeclared (first use this function)
    main.cpp:129: error: `totalD' undeclared (first use this function)
    main.cpp:129: error: `calculateStation' undeclared (first use this function)
    main.cpp:134: error: `printmainHeading' undeclared (first use this function)
    main.cpp:135: error: `printcolumnHeading' undeclared (first use this function)
    main.cpp:136: error: `date' undeclared (first use this function)
    main.cpp:136: error: `inputString' undeclared (first use this function)
    main.cpp:136: error: `position' undeclared (first use this function)
    main.cpp:137: error: `i' undeclared (first use this function)
    main.cpp:137: error: `a' undeclared (first use this function)
    main.cpp:137: error: `b' undeclared (first use this function)
    main.cpp:137: error: `c' undeclared (first use this function)
    main.cpp:137: error: `d' undeclared (first use this function)
    main.cpp:137: error: `calculateTotalStation' undeclared (first use this function)
    main.cpp:138: error: `total' undeclared (first use this function)
    main.cpp:119: warning: unused variable 'Total'
    main.cpp:120: warning: unused variable 'contotal'
    Functions and variables are still not declared. This chunk of code here is a tip of a very big iceberg, so declare stuff the right type and make sure that function signatures match.
    Code:
    // you should assign characters here, and not part of a string
    // or whatever this is
     date [i] = ipString.substr; 
     time [i]= ipString.substr;
    Last edited by whiteflags; 06-01-2006 at 12:18 AM.

  3. #18
    Registered User
    Join Date
    Apr 2006
    Posts
    22
    i will tru get rid of the array and use piping to do it i will post what i've done and see if u can help me

  4. #19
    Registered User
    Join Date
    Apr 2006
    Posts
    22
    please try to help me solve my pro
    Last edited by halloula; 06-01-2006 at 01:49 AM.

  5. #20
    Registered User
    Join Date
    Apr 2006
    Posts
    22
    i tried to get rid of the array and i got this in my program but still i doesn't do the calculation that i want to have a look and try to figure out with me the problem
    Code:
    #include <iostream>
    using namespace std;
    
    int main() {
     
        string id, id2, tp;
        char gate;
        int i=0, j=0, temp=0;
        float a , b,c,d, total =0;
        string adress, name, heading;
        
        
       heading = " Interstate Mototrway Pty Ltd invoice statements";
       cout << heading<<endl;
       cout <<"________________________________________________"<<endl;
       
       for (i=0; i< 36; i++)
       {
       
                if (i=0)
                {
                        cerr << "Cutomer id:";
                        cin >> id;
                        if(cin.fail())
                        break;
                        cerr << " Station gate:";
                        cin >> gate;
                        if (cin.fail())
                        break;
                        cerr << "Comments: ";
                        cin >> ws;;
                        getline(cin, name);
                        getline(cin, adress);
                        if (cin.fail()) 
                        break;
                        cout << " 1. Customer ID:"<<id<<endl;
                        cout << " 2. Full Name:"<< name<<endl;
                        cout << " 3. Adress:" << adress<< endl;
                }
                else
                {
                    
                     cerr << "Cutomer id:";
                        cin >> id;
                        if(cin.fail())
                        break;
                        cerr << " Station gate:";
                        cin >> gate;
               if ( gate == '@')
               {
                    cerr << "Comments: ";
                  cin >> ws;;
                             getline(cin, name);
                        getline(cin, adress);
                        if (cin.fail()) 
                        break;
                        cout << " 1. Customer ID:"<<id<<endl;
                        cout << " 2. Full Name:"<< name<<endl;
                        cout << " 3. Adress:" << adress<< endl;
               }
                else if (gate =='A')
                {
                     cerr << "Comments: ";
                  cin >> ws;;
                        getline(cin, adress);
                        if (cin.fail()) 
                        break;
                        cout << " Adress:"<< adress<<endl;
                        cout << "          " << gate<< endl; 
                        a++;
                }
                else if (gate == 'B')
                             {
                                 cerr << "Note: ";
                  cin >> ws;;
                                 getline(cin, adress);
                        if (cin.fail()) 
                        break;
                        cout << " Adress:"<< adress<<endl;
                        cout << "          " << gate<< endl; 
                        b++;
                }
                
                else if (gate == 'C')
                {
                     cerr << "Comments: ";
                     cin >> ws;;
                                 getline(cin, adress);
                        if (cin.fail()) 
                        break;
                        cout << " Adress:"<< adress<<endl;
                        cout << "          " << gate<< endl; 
                        c++;
                }
                else if (gate == 'D')
                {
                     cerr << "Comments: ";
                     cin >> ws;;
                    getline(cin, adress);
                        if (cin.fail()) 
                        break;
                       cout<< "              :"<< a<< "   * $2.20 = " << "$"<< (a*2.20)<<endl;
                       cout<< "              :"<< b<< "   * $2.80 = " << "$"<< (b*2.20)<<endl;
                       cout<< "              :"<< c<< "   * $2.30 = " << "$"<< (c*2.20)<<endl;
                       cout<< "              :"<< d<< "   * $3.80 = " << "$"<< (d*2.20)<<endl;
                       cout<< " TOTAL IS" << "$"<< a+b+c+d<< endl;
                       cout<<"____________________________________________________"<<endl;
                       cout<<" please make payment as soon as possible"<< endl;
                }
         }
    }
    }

  6. #21
    Registered User
    Join Date
    Apr 2006
    Posts
    22
    that's what i got so far but the rogram won't compile i gt a problem saying multipe function of main plz help me
    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;
    }

  7. #22
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,696
    You have posted two programs.

    When you try to compile two source files with main in them in the same project, you will get that error. You can compile them in separate projects, and use piping to make the two programs work with each other: where one "parent" program will call the "child" program.

    However, in your particular case, the program is simple enough where you do not need to look at this option, I think. It depends on the directions for your homework: if your teacher wants you to do that, then you'd have to.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 12:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 12:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 09:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21