
-----------------------------------
El Cid
Fri Mar 03, 2006 12:40 am

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!

-----------------------------------
[Gandalf]
Fri Mar 03, 2006 12:50 am


-----------------------------------
Welcome to the forums, although I see you've already been here a while. :)

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
Fri Mar 03, 2006 1:03 am


-----------------------------------
Gandalf's quite right.  Oh, and you have main returning int.  So why isn't it declared as such?

-----------------------------------
wtd
Fri Mar 03, 2006 1:04 am


-----------------------------------
Oh, and there's no reason to separately declare and initialize variables like you've done here:

      ifstream problemFile;
      ofstream calculationsFile;
      problemFile.open("mp4romanletr-data.txt");
      calculationsFile.open("calculationresults.txt");

-----------------------------------
Justin_
Fri Mar 03, 2006 1:12 am


-----------------------------------
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_
Fri Mar 03, 2006 1:15 am


-----------------------------------
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
Fri Mar 03, 2006 1:17 am


-----------------------------------
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_
Fri Mar 03, 2006 1:23 am


-----------------------------------
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,




//instead of:
ofstream calculationsFile;
calculationsFile.open("calculationresults.txt");

//do this:
ofstream calculationsFile = "calculationresults.txt";



-----------------------------------
wtd
Fri Mar 03, 2006 1:45 am


-----------------------------------
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,




//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:

ofstream calculationsFile = ofstream("calculationresults.txt");

Or:

ofstream calculationsFile("calculationresults.txt");

-----------------------------------
Justin_
Fri Mar 03, 2006 1:51 am


-----------------------------------
yeah silly of me, i meant:  


ofstream shit("shit.txt");


can you see my sig by the way?

-----------------------------------
wtd
Fri Mar 03, 2006 2:03 am


-----------------------------------
It's a very nice "remote linking of images not allowed" image.
