-
(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
-
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
-
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
}
-
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 :D ).
Regards
hmm
-
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 :)
-
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.