Need Help With Error Messages.

This is a discussion on Need Help With Error Messages. within the C++ Programming forums, part of the General Programming Boards category; Okay. I've been working on my Intro to Programming assignment. My code is as follows (Code Starts) #include <fstream.h> #include ...

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    3

    Need Help With Error Messages.

    Okay. I've been working on my Intro to Programming assignment. My code is as follows
    (Code Starts)
    #include <fstream.h>
    #include <iostream.h>
    #include <cstdlib>

    int tn();
    int ui();
    int fileopen();
    int uexit();
    int uerror();
    int uinput();
    int main()
    {
    int tn=0;
    tn=uinput();
    return 0;
    }
    int uerror()
    {
    cout<<"\n Error.Try Agian. 2 to exit";
    return 0;
    }
    int uexit()
    {
    cout<<"\n Thank you. Goodbye.";
    return 0;
    }
    int fileopen()
    {
    char str[100];
    ifstream b_file("infile.dat");
    b_file>>str;
    cout<<str;
    b_file.close();
    }
    int uinput()

    int tn;
    int ui;

    do
    {
    cout<<"Press 1 to view the file\n";
    cout<<"Press 2 to exit\n";
    cin>>ui;

    switch(ui)
    {
    case 1:
    tn=fileopen();
    break;
    case 2:
    tn=uexit();
    break;
    default:
    tn=uerror();
    break;

    }

    }while (ui!=2);
    return ui;
    }(Code Ends)
    The error messages I get are:
    C:\Program Files\Microsoft Visual Studio\MyProjects\HW6\Text2.cpp(41) : warning C4518: 'int ' : storage-class or type specifier(s) unexpected here; ignored
    C:\Program Files\Microsoft Visual Studio\MyProjects\HW6\Text2.cpp(41) : error C2146: syntax error : missing ';' before identifier 'tn'
    C:\Program Files\Microsoft Visual Studio\MyProjects\HW6\Text2.cpp(41) : fatal error C1004: unexpected end of file found
    I'm using Microsoft Visual Studio 6.0 and would appreciate it if someone out there could run this program and see where I'm making my mistake. Thanks.

  2. #2
    Disturbed Boy gustavosserra's Avatar
    Join Date
    Apr 2003
    Posts
    244
    Where is the ; ate the end of int uinput()?
    And use code tags!
    Nothing more to tell about me...
    Happy day =)

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    Code:
    int uinput() { //need brace here
    
    int tn;
    int ui;
    and also use code tags when you post code

    edit: gustavosserra beat me.

  4. #4
    Geo Geo Geo-Fry
    Join Date
    Feb 2003
    Posts
    116
    edit: gustavosserra beat me.
    for those of us who are yet to realize that the messages on top came first...
    but seriously, i see people do that all the time. why? i think most people can tell the order of the posts by themselves, and those who cant will figure it out soon enough
    "You can lead a man to Congress, but you can't make him think."
    "The Grand Old Duke of York
    -He had ten thousand men.
    -His case comes up next week."
    "Roses are red, violets are blue, I'm schizophrenic, and so am I."
    "A computer once beat me at chess, but it was no match for me at kick boxing."
    "More and more of our imports are coming from overseas."
    --George W. Bush
    "If it weren't for electricity, we'd all be wacthing TV by candlelight."
    --George W. Bush

  5. #5
    NewbieUser
    Guest
    also you do not need to include <iostream.h> since <fstream.h> does it for you

  6. #6
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    Originally posted by Geo-Fry
    for those of us who are yet to realize that the messages on top came first...
    but seriously, i see people do that all the time. why? i think most people can tell the order of the posts by themselves, and those who cant will figure it out soon enough
    just so that people don't get mad when they've sufficiently answered the question. i.e. posts such as "I just posted that" etc. etc. usually posted at the same time or seconds before.

  7. #7
    Disturbed Boy gustavosserra's Avatar
    Join Date
    Apr 2003
    Posts
    244

    Talking Uhm...

    What are you both talking about? I mean, I am no good english speaker.Did Geo - Fry say that I was faster than he???
    Nothing more to tell about me...
    Happy day =)

  8. #8
    Registered User
    Join Date
    May 2003
    Posts
    3

    Thanks

    Thanks to everyone for your help. I've got it figured out now and pretty much working.

  9. #9
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    And since you include <cstdlib> you should use the new-standard headers <fstream> and <iostream> too. You should use them anyway, but you should especially avoid mixing new and old headers.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  10. #10
    Geo Geo Geo-Fry
    Join Date
    Feb 2003
    Posts
    116
    What are you both talking about? I mean, I am no good english speaker.Did Geo - Fry say that I was faster than he???
    no, i was just wondering why alpha had put "edit: gustavosserra beat me." - i was pointing out that i thought that fact was fairly obvious, and wonder why he took the time to post it.
    "You can lead a man to Congress, but you can't make him think."
    "The Grand Old Duke of York
    -He had ten thousand men.
    -His case comes up next week."
    "Roses are red, violets are blue, I'm schizophrenic, and so am I."
    "A computer once beat me at chess, but it was no match for me at kick boxing."
    "More and more of our imports are coming from overseas."
    --George W. Bush
    "If it weren't for electricity, we'd all be wacthing TV by candlelight."
    --George W. Bush

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21