GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 20-Mar-2010, 00:56
Aljazee Aljazee is offline
New Member
 
Join Date: Mar 2010
Location: UAE
Posts: 24
Aljazee is on a distinguished road
Smile

Error C1004


Hello everyone,

I am beginner and I hope someone could help me finding what is the error in my code ... there are two errors ...
  1. error C2448: '<Unknown>' : function-style initializer appears to be a function definition
  2. fatal error C1004: unexpected end of file found

CPP / C++ / C Code:
#include<iostream>
using namespace std;
#include<cmath>
#include<iomanip>
 std::setiosflags(std::ios::fixed)
	 int main(){

int grades[12]={89,78,56,66,45,98,73,33,86,61,88,93};
int counter;
double avg,sum=0.0,deviations,deviation[12],square,total=0.0,variance,sd;
cout<<setprecision(2);
cout<<setiosflags(ios::fixed);

for(counter=0;counter<11;counter++)
{
	sum=sum+grades[counter];}

avg=sum/12;
cout<<" The sum of the grades  is  "<<sum<<"  the avg is  "<<avg<<endl;


for (counter=0;counter<12;counter){
	deviations=grades[counter]-avg;
	deviation[counter]=deviations;
}

cout<<"Deviation"<<setw(15)<<"sequare"<<endl;
cout<<"__________"<<setw(14)<<"__________"<<endl;
for(counter=0;counter<12;counter++)
{
	cout<<deviation[counter]<<setw(15);
	sguare=pow(deviation[counter],2);
		cout<<square<<endl;
	total=total+square;
}
cout<<endl;
cout<<"The total of square is "<<total<<endl<<endl;
variance=total/12;
cout<<"The variance is :"<<variance<<endl<<endl;
sd=sqrt(variance);
cout<<"The Standard Deviation is :"<<sd<<endl<<endl;

return(0);
 }

  #2  
Old 20-Mar-2010, 03:14
Kimmo Kimmo is offline
Regular Member
 
Join Date: Mar 2007
Location: Finland
Posts: 388
Kimmo is a jewel in the roughKimmo is a jewel in the roughKimmo is a jewel in the rough

Re: Error C1004


Quote:
Originally Posted by Aljazee
  1. error C2448: '<Unknown>' : function-style initializer appears to be a function definition
  2. fatal error C1004: unexpected end of file found
You are using a different compiler than I am, but the errors are the same nonetheless. So let's take a quick walkthrough of the code. When compiling your code I get the following output:

Code:
main.cpp:6: error: expected constructor, destructor, or type conversion before '(' token
The error message itself might not be that useful... But basically this is my compiler's way of saying "you cannot call a function at global scope" or something along those lines. So, move the call inside main():

CPP / C++ / C Code:
	 int main(){
 std::setiosflags(std::ios::fixed)

After this correction I get:

Code:
main.cpp: In function 'int main()': main.cpp:13: error: expected ';' before 'int' main.cpp:21: error: 'grades' was not declared in this scope main.cpp:27: warning: 3rd expression in for has no effect main.cpp:28: error: 'grades' was not declared in this scope main.cpp:37: error: 'sguare' was not declared in this scope

Now, with errors it's usually the best idea to start from the top, because simple errors in the early stage of the program can cause weird error messages in the later parts. To prevent cases like this your compiler might have an option called "fatal errors" or something. Turning this option on will cause the compiler to abort at the first error message. If you look at the first message, it clearly says (this time) what is wrong:

CPP / C++ / C Code:
     std::setiosflags(std::ios::fixed); // semicolon was missing

Let's try again with this change:

Code:
main.cpp: In function 'int main()': main.cpp:27: warning: 3rd expression in for has no effect main.cpp:37: error: 'sguare' was not declared in this scope

Well what do you know, the weird error about undeclared grades vanished. There's still one error though, an undeclared sguare. Clearly, this is a typo. After correcting it to square:

Code:
main.cpp: In function 'int main()': main.cpp:27: warning: 3rd expression in for has no effect

Now the code compiles. It's a good idea to set your compiler's warning levels high. It let's you catch things like this.

CPP / C++ / C Code:
for (counter=0;counter<12;counter){

Clearly you meant to have ++counter.

After this it compiles cleanly.
  #3  
Old 20-Mar-2010, 03:45
Aljazee Aljazee is offline
New Member
 
Join Date: Mar 2010
Location: UAE
Posts: 24
Aljazee is on a distinguished road

Re: Error C1004


Thank you very much ... really I appreciate your help ..
I think I should practice more to avoid this kind of mistake

thank you again ...

 
 

Recent GIDBlogVista ?Widgets? on Windows XP by LocalTech

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 19:02.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.