5 Replies - 806 Views - Last Post: 19 September 2011 - 02:33 PM Rate Topic: -----

#1 amy310   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 04-November 10

what is wrong with this parrallel array C++ code ? 27 errors

Posted 19 September 2011 - 01:42 PM

#include<iostream>
#include<fstream>
using namespace std ;
int main(){
   int morning [8]={0};
   int evening[8]={0};
   if stream in1;
   if stream in2;
   in1.open("morningEggs.txt");
   in2.open("eveningEggs.txt");

   if(in1.is_open()){
   while(!in1.eof()){
   in1>>loc;
   in1>>num;
   morning[loc]=num;
     }
   }

   if(in2.is_open()){

   in2>>loc;
   in2num;
   evening[loc]=num;
   int loc; int num;
   int numMorn=0,numEve=0;
   int totalEggs=0,numDoz=0;}

}
in1.close();
in2.close();
cout<<"Coup # "<<"/tMorning"<<"\t Evening"<<endl;
for(int i=1;i<8;i++){
cout<<i<<morning[i]<<evening[i]<<endl;
numMorn = morning[i]+numMorn;
numEve = evening[i]+numEve;
}
totalEggs = numMorn+numEve;
numDoz = totalEggs/12;
return 0;
}


these are the errors i keep getting . this code was given by the teacher and it supposedly works fine but when i tried to compile it exactly as he gave it to me this is what happens , if anyone can give me some pointers on what i'm doing wrong i'd really appreciate it .

cpp: In function `int main()':
7: error: expected `(' before "stream"
8: error: expected `(' before "stream"
9: error: `in1' undeclared (first use this function)
9: error: (Each undeclared identifier is reported only once for each function it appears in.)
10: error: `in2' undeclared (first use this function)
14: error: `loc' undeclared (first use this function)
15: error: `num' undeclared (first use this function)
23: error: `in2num' undeclared (first use this function)
At global scope:
30: error: expected constructor, destructor, or type conversion before '.' token
30: error: expected `,' or `;' before '.' token
31: error: expected constructor, destructor, or type conversion before '.' token
31: error: expected `,' or `;' before '.' token
32: error: expected constructor, destructor, or type conversion before '<<' token
32: error: expected `,' or `;' before '<<' token
33: error: expected unqualified-id before "for"
33: error: expected `,' or `;' before "for"
33: error: expected constructor, destructor, or type conversion before '<' token
33: error: expected `,' or `;' before '<' token
33: error: expected constructor, destructor, or type conversion before '++' token
33: error: expected `,' or `;' before '++' token
38: error: expected constructor, destructor, or type conversion before '=' token
38: error: expected `,' or `;' before '=' token
39: error: expected constructor, destructor, or type conversion before '=' token
39: error: expected `,' or `;' before '=' token
40: error: expected unqualified-id before "return"
40: error: expected `,' or `;' before "return"
41: error: expected declaration before '}' token
Process terminated with status 1 (0 minutes, 0 seconds)
27 errors, 0 warnings

Is This A Good Question/Topic? 0
  • +

Replies To: what is wrong with this parrallel array C++ code ? 27 errors

#2 Salem_c   User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 2160
  • View blog
  • Posts: 4,225
  • Joined: 30-May 10

Re: what is wrong with this parrallel array C++ code ? 27 errors

Posted 19 September 2011 - 01:51 PM

07 if stream in1;
08 if stream in2;
ifstream is one word, not two.
Was This Post Helpful? 1
  • +
  • -

#3 Curtis Rutland   User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 5103
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: what is wrong with this parrallel array C++ code ? 27 errors

Posted 19 September 2011 - 01:52 PM

I'm guessing that the issue is that the if streams should be ifstreams.
Was This Post Helpful? 1
  • +
  • -

#4 jimblumberg   User is offline

  • member icon

Reputation: 5487
  • View blog
  • Posts: 17,062
  • Joined: 25-December 09

Re: what is wrong with this parrallel array C++ code ? 27 errors

Posted 19 September 2011 - 02:11 PM

Looking at the errors and the code this looks more like an exercise in reading and fixing errors.

If that is the case start with the first error and work through each error one at a time. The error messages tell you what line the problem was detected and some kind of message about the type of error:

Jim
Was This Post Helpful? 1
  • +
  • -

#5 amy310   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 04-November 10

Re: what is wrong with this parrallel array C++ code ? 27 errors

Posted 19 September 2011 - 02:17 PM

corrected the ifstreams error so now i have lines 14 - 41 same errors as above .

this actually is supposed to be the correct code to a class exercise we did .....and not for finding/fixing errors. i just wanted to compile and run it so i'd have a better understanding of what i'm trying to do .
i am trying whatever i can think of to fix it and will update if i make any improvement , thank you all for your help so far
Was This Post Helpful? 0
  • +
  • -

#6 Curtis Rutland   User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 5103
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: what is wrong with this parrallel array C++ code ? 27 errors

Posted 19 September 2011 - 02:33 PM

Well, it's not even close to correct. It looks like someone took the lines and jumbled them all up. The declaration for "loc" and "num" are created after they're tried to be used. This is a total mess. I'd ask the professor for a corrected copy.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1