0

Hello,

On lines 70 & 75, the word col is marked as a syntax error. When I hover my mouse over, it tells me that Error: expression must have pointer-to-object type. Why am I getting this error and how do I fix it?

This program prompts & reads the file name from the user for the scores data. I am currently working on letter b which is to Load the scores data into the scores array. I am stuck. :/

col = column

#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;

void readfile();
void loadscores(int , int);

char upcase(char);		

int main()
{
	char menuChoice;
	bool userNotDone = true;

	int scores1, 
		scores2; 
		
	while (userNotDone)
	{
	cout << " Menu" ;
	cout << "\n\n";
	cout << "			a. Open Files\n";
	cout << "			b. Load Scores";
	cout << "			x. Exit\n\n";
	cout << "			enter choice: ";

	cin >> menuChoice;
	
	switch (upcase(menuChoice))
	{
		case 'A':   readfile();
			system("pause");
			break;
		case 'B':	loadscores(scores1, scores2);
			system("pause");
			break;	
		case 'X': cout << "exist\n";
			userNotDone = false;
			break;
		default: cout << "error" ; 
	}	
	} 

	return 0;
}
void readfile()
{
	fstream inData;
	ofstream newFile;
	ifstream readFile;

	string fileName = "file Name";
	srand(3);
	
	newFile.open(fileName.c_str()); 
}
void loadscores(int scores1, int scores2)
{
	ofstream newFile;
	ifstream readFile;
	string fileName;

	int col = 0;
	readFile.open(fileName.c_str());
	
	readFile >> scores1[col] >> scores2[col];

	while(!readFile.eof()) 
	{
		col++;
		readFile >> scores1[col] >> scores2[col];
	}
	readFile.close();
}

char upcase(char inComing)
{
	if(inComing >= 'a' && inComing <= 'z')
		inComing -= 32;
	return inComing;
}
Attachments error_list.jpg 34.09 KB
2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by Labdabeta
0

The problem is not the col variable. It is the scores1 and scores2 variables. Basically you tried to access the member of an array (arrays are just pointers) of a variable that was not even an array. The [] operators are almost exclusively for array and array-like objects.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.