Results 1 to 6 of 6

Thread: (old-style formal list?)

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2001
    Location
    England
    Posts
    312

    (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

  2. #2
    Member
    Join Date
    May 2001
    Location
    UK
    Posts
    40
    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

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  4. #4
    Member
    Join Date
    May 2001
    Location
    UK
    Posts
    40

    Red face

    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

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    May 2001
    Location
    England
    Posts
    312
    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

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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
  •  



Click Here to Expand Forum to Full Width