|
-
Nov 10th, 2001, 08:56 AM
#1
Thread Starter
Hyperactive Member
(old-style formal list?)
im gettingh this error...
C:\My Coding Stuff\C++\First Time c++\loops and stuff\loops and stuff.cpp(9) : error C2447: missing function header (old-style formal list?)
for this code...
Code:
#include "stdafx.h"
#include<iostream.h>
int main();
{
int rating;
cout<<"how would you rate this program on a scale of 1 - 10 : ";
cin>>rating;
if(rating < 2)
cout<<rating<<"surely not, that is REALLY bad";
elseif(rating < 4 && > 2);
cout<<rating<<"hmm, thats not too bad i suppose!";
return(0)
}
now obviously, im quite new at this (well, just restarted from what wasnt a very wide knowledge)
im sure i had this when i was coding before and it was something stupid, the answer anyway
thanx
-
Nov 10th, 2001, 09:18 AM
#2
Member
Hi JafferAB
Couple of errors:
1.
// int main();
should read
// int main () i.e no semi-colon
2.
//elseif
should read
//else
working version:
#include<iostream.h>
int main()
{
int rating;
cout<<"how would you rate this program on a scale of 1 - 10 : ";
cin>>rating;
if(rating < 2)
cout<<rating<<"surely not, that is REALLY bad";
else
(rating < 4 && rating > 2);
cout<<rating<<"hmm, thats not too bad i suppose!";
return(0);
}
HTH
hmm
-
Nov 10th, 2001, 09:43 AM
#3
hmm: your version will compile but notdo what it should. else cannot be followed by a boolean expression. Your code does this:
if the rating is smaller than 2 then write the rating and the sentence "surely not, that is REALLY bad" to the screen (note that there is no space between the number and the sentence).
else the computer will look if rating is smaller than 4 and larger than 2, and do nothing with the result.
In any case the pc will the output the rating and "hmm, thats not too bad i suppose".
This version really works:
Code:
#include "stdafx.h"
#include<iostream.h>
int main() // error was here: semicolon after function name
{
int rating;
cout<<"how would you rate this program on a scale of 1 - 10 : ";
cin>>rating;
if(rating <= 2) // I included 2 in this. Before it was nowhere.
cout<<rating<<" surely not, that is REALLY bad"; // I inserted one space
else if(rating < 4 && > 2) // there is no elseif but you can use else if. Also, there is no semicolon after the brackets.
cout<<rating<<" hmm, thats not too bad i suppose!"; // again a space
return(0); // semicolon needed
}
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 10th, 2001, 09:53 AM
#4
Member
Hello Cornedbee,
Points taken. I should have taken a bit more time considering my reply...apologies JafferAB I've still got my learner plates on ).
Regards
hmm
-
Nov 10th, 2001, 10:17 AM
#5
Thread Starter
Hyperactive Member
no problem, thanx for repying anyways..
i know i shoudlnt have a ; at the int main() bit, i dont know why i put it there, but thats all iw as looking for really, i woul dhave worked the rest out :Y:Y
but thatnx for all teh help
-
Nov 10th, 2001, 01:10 PM
#6
A tip: by double-clicking on the error you are taken to the line. If the error is not there, check the sourroundings, especially for missing semicolons. They usually create errors 1 or 2 lines later.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|