Counter

This is a discussion on Counter within the C++ Programming forums, part of the General Programming Boards category; OK, I wish to do a Counter that will Count the Number of People that Enter 'Y' Code: using namespace ...

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    12

    Counter

    OK, I wish to do a Counter that will Count the Number of People that Enter 'Y'

    Code:
    using namespace std;
    int count = 0;
    Code:
                Newpassenger passenger;
                cin >> passenger.seat_number;
                
                
                while (passenger.seat_number > 0 && passenger.seat_number <=100)
                {
                    cout << "Enter passengers Name:";
                    cin >> passenger.name;
                    
                    cout << "Do you have an Onward Flight: (Y/N)";
                    cin >> passenger.onward;
                    
                    if(passenger.onward == 'Y') // Im getting an ERROR Comparsion between pointer and integer('char*' and 'int')
                        
                   count ++; //ERROR Reference to 'count is ambiguous
                    return count; // ERROR Reference to 'count is ambiguous
    Code:
    if (choice ==5) 
            {
                cout << "The Number of Passengers that have an OnWard flight is" << " " << count << endl;   ERROR // Reference to 'count is ambiguous
                
            }

  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,262
    And the type of onward would be what?

    Also, I can tell what you've done that is giving you the ambiguity, but as you haven't actually shown the code with the problem I can't go, "look there it is!".
    Show more code. Whole functions at the very least.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  3. #3
    Registered User
    Join Date
    Apr 2011
    Posts
    12
    Code:
    using namespace std;
    
    struct Newpassenger
    { 
        int seat_number;
        char name[20];
        char onward[3];
    };
    int count = 0;
    /*****************************************************************************************************************/
    
    
    
    /*****************************************************************************************************************/
    
    
    int main() 
    {
        int i;


    Code:
    if (choice == 1) // Add New Record..
                
                
    		{
                fstream Airline ("AirLine.text", ios::out | ios::in |ios::binary); 
                if(!Airline)
                {
                    cout << "File Could not be opened." << endl;  
                    system("PAUSE");
                    exit (1); 
                }
                
                
                cout << "Enter Seat Number to Write"
                <<"(1 to 100, 0 to end )?";
                
                
                Newpassenger passenger;
                cin >> passenger.seat_number;
                
                
                while (passenger.seat_number > 0 && passenger.seat_number <=100)
                {
                    cout << "Enter passengers Name:";
                    cin >> passenger.name;
                    
                    cout << "Do you have an Onward Flight: (Y/N)";
                    cin >> passenger.onward;
                    
                    if(passenger.onward == 'Y') // Im getting an ERROR Comparsion between pointer and integer('char*' and 'int')
                        
                   count ++; //ERROR Reference to 'count is ambiguous
                    return count; // ERROR Reference to 'count is ambiguous
                    
                    
                    Airline.seekp((passenger.seat_number - 1 ) * sizeof(Newpassenger));
                    
                    Airline.write(reinterpret_cast<const char *>(&passenger), sizeof (Newpassenger));
                    
                    cout << "\nEnter Seat Number: ?";
                    cin >> passenger.seat_number;
                }
                Airline.close();
                cout << endl;
            }
    Code:
     if (choice ==5) 
            {
                
             cout << "The Number of passengers that have onward flights are: " << " " <<count <<endl;
    cout <<endl;
            }
    Last edited by jackirl; 11-27-2011 at 06:01 AM.

  4. #4
    Registered User
    Join Date
    Apr 2011
    Posts
    12
    What i like to do is....

    search through all the records from start to finish and each time a record with onward connections is found the total count should be increased by 1. At the end the total count is output.

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,171
    What part are you having problems with specifically?
    Also, in case you are allowed to use std::string, use it.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  6. #6
    Registered User
    Join Date
    Apr 2011
    Posts
    12
    The Errors are the problem im facing

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Page File counter and Private Bytes Counter
    By George2 in forum Tech Board
    Replies: 0
    Last Post: 01-31-2008, 02:17 AM
  2. The counter
    By Gordon in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 05:50 AM
  3. Help With a Counter
    By Halo in forum C++ Programming
    Replies: 3
    Last Post: 12-15-2005, 03:03 PM
  4. counter
    By Colonial Viper in forum C++ Programming
    Replies: 4
    Last Post: 04-01-2005, 10:44 AM
  5. Help!Counter...
    By Unregistered in forum C++ Programming
    Replies: 4
    Last Post: 05-25-2002, 01:14 AM

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