Thread: Help with wierd error

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    15

    Help with wierd error

    I've been told to make a program that takes in the data for 3 soccer players throughout 10 games. when i run it so far (i havent made the print function yet) it asks for the name of the player, then enters the nested loop and never stops for input (at any of the "cin >>" spots) any ideas as to why?



    Code:
    #include <iostream.h>
    
    
    int main ()
    {
    
    int names[3];
    int shots[10];
    int shotsongoal[10];
    int goals[10];
    
    for (int i=1; i<=3; i++)
            {
            cout << "Player " << i << "'s name: " << endl;
            cin >> names[i];
    
            for (int x=1; x<=10; x++)
                    {
                    cout << "Game " << x << endl;
                    cout << "Shots: \n";
                    cin >> shots[x];
                    cout << "Shots on Goal: \n";
                    cin >> shotsongoal[x];
                    cout << "Goals: \n";
                    cin >> goals[x];
                    }
            }
    system("PAUSE");
    return 0;
    }

  2. #2
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    It's because you are entering string (character) data into names[i], but names is an int array;

    I would suggest you use std::string names[3];

    be sure to include <string>

  3. #3

  4. #4
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    one other thing I should had mentioned, unless you are using an old comipler or have some other compelling reason, you really should be using <iostream> and not <iostream.h>

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  4. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  5. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM