0

i get a couple error messages when i try to compile this program...I dont understand how to fix them and i was hoping for some help.....The error messages i get are:

error C2146: syntax error : missing ';' before identifier 'inData'
error C2501: 'ifstream' : missing storage-class or type specifiers
fatal error C1004: unexpected end of file found

here is my code:

#include <iostream>
#include <fstream>
#include <string.h>
#include <stdio.h>

void Get_Choice(char);
void Process_Choice(float a[][100],char,int&,int&);
void Load(float a[][100],int&,int&);
void Display(float a[][100],int&,int&);
float Average(float a[][100],int&,int&);
float LargestNum(float a[][100],int&,int&);
float SmallestNum(float a[][100],int&,int&);
int Search(float a[][100],int&,int&);
int Between(float a[][100],int&,int&);
char choice;
bool die =1;

ifstream inData;
ofstream outData;

void main()
{
   using namespace std;
   //ifstream inData;
   //ofstream outData;
   
   int rowSize=0,colSize=0;
   float array[100][100]; 
   outData.open("data.dat"); //opens an output file  
   
   while(die)
   {
   cin.clear();            
   Get_Choice(choice);  //calls the menu function
   Process_Choice(array[][100],choice,colSize,rowSize);
   }
}
//prints out the menu
void Get_Choice(char choice)
{
     outData<<endl;
     cout<< "The following is the menu" << endl;
     outData<<"The following is the menu" << endl;
     cout<<endl;
     outData<<endl;
     cout<< "a. Load the array" << endl;
     outData<< "a. Load the array" << endl;
     cout<< "b. Sort the Array in ascending order" << endl;
     outData<< "b. Sort the Array in ascending order" << endl;
     cout<< "c. Average the Numbers" << endl;
     outData<< "c. Average the Numbers" << endl;
     cout<< "d. Find the smallest number" << endl;
     outData<< "d. Find the smallest number" << endl;
     cout<< "e. Find the largest number" << endl;
     outData<< "e. Find the largest number" << endl;
     cout<< "f. Search for a Number" <<endl;
     outData<< "f. Search for a Number" <<endl;
     cout<< "g. Check how many numbers are between two numbers" <<endl;
     outData<< "g. Check how many numbers are between two numbers" <<endl;
     cout<< " ENTER z TO QUIT " << endl;
     outData<< " ENTER z TO QUIT " << endl;
     
     cout<< "Enter your choice"<< endl;
     outData<< "Enter your choice"<< endl;
     cin >> choice;
}

//executes function based on users input
void Process_Choice(float array[][100],char choice,int& rowSize,int& colSize)
{
     switch(choice)
     {
           case 'a':
                   Load(array[0][100],rowSize,colSize);
                   Display(array[0][colSize],rowSize,colSize);
                   break; 
           case 'b':cout<<"Average: ";
                    outData<<"Average: ";
                    Average(array[0][colSize],rowSize,colSize);
                    break;
           case 'c': cout<<"Largest Number in Array: ";
                     outData<<"Largest Number in Array: ";
                     LargestNum(array[0][colSize],rowSize,colSize);
                     break;
           case 'd': cout<<"Smallest Number in Array: ";
                     outData<<"Smallest Number in Array: ";
                     SmallestNum(array[0][colSize],rowSize,colSize);
                     break;
           case 'e': cout<< "The number is at position(s): ";
                     outData<< "The number is at position(s): ";
                     Search(array[0][colSize],rowSize,colSize);
                     break;
           case 'f': cout<<"Numbers between: "<<
                     outData<<"Numbers between: ";
                     Between(array[0][colSize],rowSize,colSize);
                     break;
           case 'z': cout<<"EXIT"<<endl;
                   die = 0;
                   break;
           default:
                    cout<<"INVAILD ENTRY"<<endl;
                    outData<<"INVAILD ENTRY"<<endl; 
                    break;
        }
}    

//loads array
void Load(float array[][100],int& colSize,int& rowSize){
{     
     cout<< "Enter the row size then the column size: "<<endl;
     outData<< "Enter the row size then the column size: "<<endl;
     cin>>rowSize;
     cin>>colSize>>endl;
     
     char answ;
      
      //prompts the user for keyboard of file input
      cout<< "Would you like to input from File or Keyboard" << endl;
      outData<< "Would you like to input from File or Keyboard" << endl;
      cout<< "Enter 'f' or 'k'" << endl;
      outData<< "Enter 'f' or 'k'" << endl;
      cin>> answ;
      
      //Keyborad input
      if(answ == 'k')
      {
            cout<< "Enter all the data at once or (Ctrl-Z to quit)" << endl;
            outData<< "Enter all the data at once or (Ctrl-Z to quit)" << endl;
            int i=0;
            int j=0;
            
            while(cin)
            {
            
                 for(i=0;i<rowSize;i++)
                 {          
                     for(j=0;j<colSize;j++)
                     {            
                           cin >> array[i][j];
                           outData<< array[i][j]<< " ";
                     }
                 }
            }
      }
      else
      {
           string fileName;
           
           cout<< "Input file name, then press Ctrl-D, Enter" << endl;
           outData<< "Input file name, then press Ctrl-D, Enter" << endl;
           cin >> fileName;
           inData.open(fileName.c_str());
                          
          int i=0,j=0;
          while(inData)
          {
             for(i=0;i<rowSize;i++)
             {          
                 for(j=0;j<colSize;j++)
                 {            
                      cin >> array[i][j];
                      outData<< array[i][j]<< " ";
                 }
             }
          }  
      }
}

//displays the array     
void Display(float array[][100],int& colSize, int& rowSize)
{
     int row=0,col=0;
     for(row = 0;row < rowSize;row++)
     {
         for(col = 0; col<colSize; col++)
         {        
                 cout<< array[row,col];
                 outData<< array[row,col];
         }     
     cout<<endl;
     outData<<endl;
     }
}

//finds the average of the numbers in the array
float Average(float array[][100],int& colSize, int& rowSize)
{
     
      int row=0,col=0;
      float sum;
      for(row = 0;row < rowSize;row++)
      {
         for(col = 0; col<colSize; col++)
             sum = sum + array[row][col];
      }
      
      return sum / float(row * col);
}

//finds the larest number in the array
float Largest(float array[][100],int& colSize, int& rowSize)
{
      
      int row=0,col=0;
      float large = 0.0;
      
      for(row = 0;row < rowSize;row++)
      {
         for(col = 0; col<colSize; col++)
         {
             if (array[row][col]> large)
                 large = array[row][col];
         }
      }
  return large;
}

//finds the smallest number in the array
float Smallest(float array[][100],int& colSize, int& rowSize)
{
      int row =0,col=0;
      float small = 0.0;
      for(row = 0;row < rowSize;row++)
      {
         for(col = 0; col<colSize; col++)
         {
                 if (array[row][col]< small)
                    small = array[row][col];
         }
      }
  return small;
}

//finds the values in between two numbers
int Between(float array[][100],int& colSize, int& rowSize)
{
    int row=0,col=0;
    int num1,num2;
    int tally =0;
    cout<<"Enter the smallest number: "<<endl;
    outData<<"Enter the smallest number: "<<endl;
    cin>>num1>>endl;
    cout<<"Enter the larger number: "<<endl;
    outData<<"Enter the larger number: "<<endl;
    cin>>num2>>endl;
    
    for(row = 0;row < rowSize;row++)
    {
         for(col = 0; col<colSize; col++)
         {
               if((array[row][col]>num1)&&(array[row][col]<num2))
                     tally++;
         }
    }
    
    return tally;
}

//searches the array for a value
int Search(float array[][100],int& colSize, int& rowSize)
{
    float target = 0;
    bool done = 0;
    int row=0,col=0,tally;    
    cout<<"Enter target number: "<<endl;
    outData<<"Enter target number: "<<endl;
    cin>>target;
    
    while(row<rowSize)
    { 
       while(col<colSize)
       {
           if(array[row][col] == target)
           {
               tally++;
               col++;
           }
       }
       row++;
    }      
    return tally;
}
2
Contributors
3
Replies
4
Views
12 Years
Discussion Span
Last Post by Narue
0

If you're going to do using namespace std, put it immediately after your includes. As it is, you're using ifstream and ofstream without qualifying the namespace.

0

thanks but now im getting this error about by fuctions:

error C2664: 'Load' : cannot convert parameter 1 from 'float' to 'float [][100]'
There is no context in which this conversion is possible

any ideas?

0

>error C2664: 'Load' : cannot convert parameter 1 from 'float' to 'float [][100]'
You're passing a float but the function expects a two dimensional array of floats. The fix for this should be obvious.

This article 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.