Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Compilation Error
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
El Cid




PostPosted: Fri Mar 03, 2006 12:40 am   Post subject: Compilation Error

I am having trouble debugging this C++ programming I'm writting for class. I am not too worried about semantics problems, because I can fix them once this compiles. But the thing is, it is refusing to compile. The Dev-Cpp warns that line 14 (prototype for the function readNumber) has too few arguments to function..., and I decided that I needed help after banging my head against the screen for a couple of hours.

Thanks ofr your help in advance!



Source.cpp
 Description:
Source code for the program

Download
 Filename:  Source.cpp
 Filesize:  4.76 KB
 Downloaded:  225 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
[Gandalf]




PostPosted: Fri Mar 03, 2006 12:50 am   Post subject: (No subject)

Welcome to the forums, although I see you've already been here a while. Smile

Your function, readNumber(), has two parameters, an ifstream and an ofstream, yet on line 37 you only pass problemFile. Try adding an ofstream into that function call.
wtd




PostPosted: Fri Mar 03, 2006 1:03 am   Post subject: (No subject)

Gandalf's quite right. Oh, and you have main returning int. So why isn't it declared as such?
wtd




PostPosted: Fri Mar 03, 2006 1:04 am   Post subject: (No subject)

Oh, and there's no reason to separately declare and initialize variables like you've done here:

code:
      ifstream problemFile;
      ofstream calculationsFile;
      problemFile.open("mp4romanletr-data.txt");
      calculationsFile.open("calculationresults.txt");
Justin_




PostPosted: Fri Mar 03, 2006 1:12 am   Post subject: (No subject)

Hi El Cid, you mentioned that your compiler fed you the error "prototype for function has too few arguments"

If you understand what a function prototype is, and what an argument is, you should realize that the compiler is being very specific. The fact that you asked this question suggests you didn't understand what the compiler was saying. I hope now you do. If not, I could explain.

And you know how you declared all your function prototypes to return something? It's the same situation with main()....
Justin_




PostPosted: Fri Mar 03, 2006 1:15 am   Post subject: (No subject)

True wtd, but I've seen many examples where they declare it like that. It's not something that El Cid should really worry about...
wtd




PostPosted: Fri Mar 03, 2006 1:17 am   Post subject: (No subject)

It is actually very important.

"All other things being equal, shorter code is better code."

It's easier to make sense of, and that makes it easier to fix.
Justin_




PostPosted: Fri Mar 03, 2006 1:23 am   Post subject: (No subject)

I agree, I find it is more concise but I'm sure he probably doesn't even know how to initialize the file on the same line.

Here is what we are talking about El Cid,



c++:

//instead of:
ofstream calculationsFile;
calculationsFile.open("calculationresults.txt");

//do this:
ofstream calculationsFile = "calculationresults.txt";

Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Fri Mar 03, 2006 1:45 am   Post subject: (No subject)

Justin_ wrote:
I agree, I find it is more concise but I'm sure he probably doesn't even know how to initialize the file on the same line.

Here is what we are talking about El Cid,



c++:

//instead of:
ofstream calculationsFile;
calculationsFile.open("calculationresults.txt");

//do this:
ofstream calculationsFile = "calculationresults.txt";



This particular example can be a bit confusing. It depends on C++ performing implicit conversions. I would suggest either:

code:
ofstream calculationsFile = ofstream("calculationresults.txt");


Or:

code:
ofstream calculationsFile("calculationresults.txt");
Justin_




PostPosted: Fri Mar 03, 2006 1:51 am   Post subject: (No subject)

yeah silly of me, i meant:

c++:

ofstream shit("shit.txt");


can you see my sig by the way?
wtd




PostPosted: Fri Mar 03, 2006 2:03 am   Post subject: (No subject)

It's a very nice "remote linking of images not allowed" image.
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 11 Posts ]
Jump to:   


Style:  
Search: