Help urgent please

This is a discussion on Help urgent please within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream> #include <iomanip> #include <string> #include <fstream> #include <cstdlib> using namespace std; void ReadPlayerInfo(ifstream& myIn, string NameArray[], int ...

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    68

    Help urgent please

    Code:
    #include <iostream>
    #include <iomanip>
    #include <string>
    #include <fstream>
    #include <cstdlib>
    
    using namespace std;
    
    void ReadPlayerInfo(ifstream& myIn, string NameArray[], int idArray[], int& size);
    void ReadProcessBatting (ifstream& myIn2, const int id [], float batAvg [], int walkArray[],int &size);
    void ProcessRecord(string batRec, float& batAvgRunning, int& walk);
    int SearchPosition(const int idArray[], int id, int size);
    void PrintTable(string nameArray[],int idArray[],float averageArray[],int walkArray[],int size);
    int FindHigh(float averageArray[], int size);
    int FindLow(float averageArray[], int size);
    
    int main()
    {
    	//Declare Variables
    	string NameArray[20];
        string batRec;
        int idArray[20];
        int size = 20;
        int id[20];
        int walkArray[20];
        int walk = 0;
        float batAvg[20];
        float batAvgRunning = 0;
        float averageArray[20]; 
    	
    	int i;
    	
    	//Begin opening files
    	string PlayerRecordsFile;
    	string PlayerBattingFile;
    	
    	ifstream myIn;
    	ifstream myIn2;
    	
    	cout << "Enter file name that contains player records: ";
    	cin >> PlayerRecordsFile;
    	myIn.open(PlayerRecordsFile.c_str());
    	
    	while (!myIn)
    	{
    		cout << "Enter file name that contains player records: ";
    		cin >> PlayerRecordsFile;
    		myIn.open(PlayerRecordsFile.c_str());
    	}
    	
    	ReadPlayerInfo(myIn, NameArray, idArray, size);   
    	
    	for (i=0;i<size;i++)
        {
    		cout << NameArray[i] << ' ' << idArray[i] << endl;
        }
    
    	cout << "Enter file name that contains batting data: ";
    	cin >> PlayerBattingFile;
    	myIn2.open(PlayerBattingFile.c_str());
    	
    	while (!myIn2)
    	{
    		cout << "Enter file name that contains batting data: ";
    		cin >> PlayerBattingFile;
    		myIn2.open(PlayerBattingFile.c_str());
    	}
    	
    	for (i=0;i<size;i++)
        {
    		ReadProcessBatting(myIn2, id, batAvg, walkArray, size);
    	}
        
    
    	
    
    	myIn.close();
    	myIn.clear();
    	myIn2.close();
    	myIn2.clear();
    	return 0;
    		
    }
    
    void ReadPlayerInfo(ifstream& myIn, string NameArray[], int idArray[], int& size)
    {
    	string playerName;
    	int playerNumber;
    	int i;
    	for (i=0;i<size;i++)
    	{
    		myIn >> playerName;
    		NameArray[i] = playerName;
    		myIn >> playerNumber;
    		idArray[i] = playerNumber;
    	}
    }
    
    void ProcessRecord(string batRec, float& batAvgRunning, int& walk)
    {
    	int x = 0;
    	char choice;
    	float hit = 0;
    	float out = 0;
    	while (x < batRec.length())
    	{
    		choice = batRec[x];
    		x++;
    	
    		switch(choice)
    		{
    			case 'O':
    				out++;
    				break;
    			case 'H':
    				hit++;
    				break;
    			case 'W':
    				walk++;
    				break;
    			default:
    				break;
    		}
    	}
    	
    	cout << "Outs: " << out << endl;
    	cout << "Hits: " << hit << endl;
    	cout << "Walks: " << walk << endl;
    	batAvgRunning = (hit/(out+hit));
    }
    
    void ReadProcessBatting(ifstream& myIn2, const int id [], float batAvg [], int walkArray[],int &size)
    {
    	int x;
    	for (x=0;x<size;x++)
    	{
    		myIn2 >> id[x];
    	}
    }
    I am getting an error on my second input file stream. Is there a way to use one file stream and open two files.

    Code:
    ola7.cc: In function 'void ReadProcessBatting(std::ifstream&, const int*, float*, int*, int&)':
    ola7.cc:137: error: no match for 'operator>>' in 'myIn2 >> *(id + ((unsigned int)(((unsigned int)x) * 4u)))'
    /usr/include/c++/4.3/istream:123: note: candidates are: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>& (*)(std::basic_istream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>] <near match>
    /usr/include/c++/4.3/istream:127: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_ios<_CharT, _Traits>& (*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>] <near match>
    /usr/include/c++/4.3/istream:134: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::ios_base& (*)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits<char>] <near match>
    /usr/include/c++/4.3/istream:170: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(bool&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:174: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short int&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:177: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:181: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(int&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:184: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:188: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long int&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:192: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:197: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long long int&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:201: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long long unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:206: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(float&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:210: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(double&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:214: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long double&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:218: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(void*&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:242: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_streambuf<_CharT, _Traits>*) [with _CharT = char, _Traits = std::char_traits<char>] <near match>
    Long error code no idea what it means.

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    You defined your int id array as const, but then you are trying to modify it.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  3. #3
    Registered User
    Join Date
    Sep 2009
    Posts
    68
    DINO!

    Ha I just noticed that. That is how our teacher had it in the PDF... I'm going to assume she is wrong there and change all that. Thanks for your help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BitWise Newbie - Needs Urgent Help
    By frodonet in forum C Programming
    Replies: 15
    Last Post: 09-26-2007, 01:58 PM
  2. display character size...(quite urgent..)
    By karthi in forum C Programming
    Replies: 10
    Last Post: 07-11-2007, 10:42 PM
  3. Linked List Need Help Urgent
    By ykchua in forum C Programming
    Replies: 5
    Last Post: 08-17-2004, 03:57 PM
  4. Help.... Urgent... Thanks!
    By weihann in forum C Programming
    Replies: 0
    Last Post: 02-27-2002, 10:15 PM

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