Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

"Cannot add two pointers error"- program using 4 parrellel array's & reading from file.

Posted on 2004-05-02
1
Medium Priority
?
991 Views
Last Modified: 2013-11-17
Hi, I have written this program and keep getting these two errors:
Compiling...
Lab14.cpp
C:\students\Lab14.cpp(91) : error C2110: cannot add two pointers
C:\students\Lab14.cpp(119) : error C2110: cannot add two pointers
Error executing cl.exe.

Lab14.exe - 2 error(s), 0 warning(s)

The errors show up on the same line-- average = (test1 + test2 + test3) / 3;  in the  searFor and displayClass functions.  

I have no clue on this one the program is as follows


//displays and averages students grades

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

//function prototype
short loadArray(string [], int [], int [], int []);
char getSelection ();
void displayClass(string [], int [], int [], int []);
void searchFor (string [], int [], int [], int []);

void main()
{
      char selection = ' ';



      //declare arrays
      string name[7] = {""};
      int test1[7] = {0};
      int test2[7] = {0};
      int test3[7] = {0};

      selection = getSelection();
      while (selection != '0')
      {
            switch (selection)
            {
            case '1': displayClass(name, test1, test2, test3);
                  break;
            case '2': searchFor (name, test1, test2, test3);
                  break;
            default: cout << "Invalid selection" << endl;
            }
            selection = getSelection();
      
      }
      cout << "Program has ended, thank you, and goodbye!" << endl;

}

//*******************************************************************
short loadArray(string name[], int test1[], int test2[], int test3[])
{
      int x = 0;
      ifstream inFile;
      inFile.open("student.dat", ios::in);
      if (inFile.is_open())
      {
            while (x < 7 && !inFile.eof())
            {
                  inFile >> name[x];
                  inFile.ignore();
                  getline(inFile, name[x], '#');
                  inFile >> test1[x];
                  inFile >> test2[x];
                  inFile >> test3[x];
                  x = x + 1;
            }//end while
            inFile.close();

      }else
            cout << "Error in opening file." << endl;

      return 0;
}

//********************************************************************
char getSelection()
{
      char selection = ' ';
      system ("cls");
      cout <<"                              Student Menu                          " << endl;
      cout <<"1. Display class names, grades, and averages" << endl;
      cout <<"2. Search by student name" << endl;
      cout <<"0 to Exit" << endl;
      cin >> selection;
      cin.ignore();
      return selection;
} // end of getSelection function

//*********************************************************************
void displayClass(string name[], int test1[], int test2[], int test3[])
{
      int x = 0;
      float average = 0.0;

      average = (test1 + test2 + test3) / 3;

      while (x < 7)
      {
            cout << name[x] << "\t" << test1[x] << "\t" << test2[x] << "\t" <<test3[x] << "\t" << average << endl;
            x = x + 1;
      }//end while
      
} //end of displayClass function

//**********************************************************************
void searchFor(string name[], int test1[], int test2[], int test3[])
{
      float average = 0.0;
      string studentName = " ";
            
      cout << "Enter the student name. (1 to return to menu): ";
      getline(cin,studentName);

      while (studentName != "1" )
      {
            int x = 0;
            while (x < 7 && name[x] != studentName)
                  x = x + 1;
            //end while

            if (x < 7)
            {
                  average = (test1 + test2 + test3) / 3;
                  cout << name[x] << "\t" << test1[x] << "\t" << test2[x] << "\t" <<test3[x] << "\t" << average << endl;
            }
            else
                  cout << "Student name was not found" << endl;
            // end if
      }
      if (studentName == "1")
      cout << "Press Enter to return to the Menu";
      getSelection();

      
}// end searchFor function


I would greatly appreciate any insight you can give me!  Thanks!
0
Comment
Question by:SinSual
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 16

Accepted Solution

by:
George Tokas earned 2000 total points
ID: 10972491
The errors you have is because at:
>>average = (test1 + test2 + test3) / 3;
you are adding 3 integers and divide them to get the average BUT
test1,2,3 are declared as arrays with 7 items(integer).
So:
to get the average you have to declare WHICH int from the array you want to add..
i.e.:
average = (test1[x] + test2[y] + test3[z]) / 3;
where x,y,z is the index in the array(0...6).

Regards,
gtokas.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question