![]() |
|
#1
|
|||
|
|||
parameter passing?Hello all
Well here is my story: I am trying to learn c++ with a sams 12 easy lessons e-book and all the gif's for the examples are missing So I am getting a handle on it but I seem to be confused when it comes to parameter passing I must be missing somthing real easy because this should be a piece of cake ... no?? Here is a simple app I am trying to write to collect skaters names and scores and then give the high,low and average scores. I am using visual c++ to compile it. CPP / C++ / C Code:
Here are the errors I am getting: --------------------Configuration: skaters - Win32 Debug-------------------- Compiling... skaters.cpp \skaters.cpp(27) : error C2275: 'Skates' : illegal use of this type as an expression skaters.cpp( skaters.cpp(27) : error C2146: syntax error : missing ')' before identifier 'skaters' skaters.cpp(27) : error C2059: syntax error : ')' skaters.cpp(2 skaters.cpp(31) : error C2181: illegal else without matching if skaters.cpp(4 skaters.cpp(53) : error C2108: subscript is not of integral type skaters.cpp(5 skaters.cpp( skaters.cpp(5 skaters.cpp(5 skaters.cpp(90) : error C2661: 'getline' : no overloaded function takes 1 parameters skaters.cpp(95) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data skaters.cpp(99) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data skaters.cpp(120) : error C2676: binary '[' : 'struct Skates' does not define this operator or a conversion to a type acceptable to the predefined operator skaters.cpp(120) : error C2228: left of '.score' must have class/struct/union type I guess my first question is whats error C2275: 'Skates' : illegal use of this type as an expression telling me? No doubt there is a problem with the way I am trying to pass the parameters?? I know this a lot of crap to look at but I appreciate any and all help on this matter!! Sincerely Jon |
|
#2
|
||||
|
||||
|
Major kudos for using code tags on your first post!!!! Thank you!
Quote:
CPP / C++ / C Code:
CPP / C++ / C Code:
Next, your prototype is: CPP / C++ / C Code:
CPP / C++ / C Code:
CPP / C++ / C Code:
__________________
Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough. -- Pearl Williams |
|
#3
|
|||
|
|||
|
Aaahhh... yes I see severl things missing now that you mention it
Thank you much for taking the time to help me out!! much appreciated I tried to edit my post above with my corrected code to save space but i cant seem to be able to find the edit button?? Well any ways I think have all my parameter passing figured out CPP / C++ / C Code:
Code:
CPP / C++ / C Code:
CPP / C++ / C Code:
sincerely Jon |
|
#4
|
||||
|
||||
|
Hi, Jon.
I'm in a bit of a hurry, so I'll be really quick about this. I hope it's ok. Quote:
Indeed, there is a time limit on post editing, mainly because we don't want you to do this! Just think about it: when someone new arrives on the forum (as a result of a google search, for example) and tries to read your post, he will see Walt giving a solution to a .... correct post! What could anyone understand then? I think this is pretty logical. Anyway, congrats on the code tags! By using them you make our work easier (which means you get better help). Quote:
Well, the problem with printing skaters[high] is that in C/C++ you can't print structs, only their members (if they aren't structs as well CPP / C++ / C Code:
As for the last errors, you should be careful about what you are working with. You pass a structure by address to the getavg function, but then try to use it as an array. That is why the compiler doesn't know what you mean by skaters[i]. skaters is just a struct here! I hope this is fine. Try to fix the error about the array passing by yourself. If you don't get that right, please come back for help (BTW, I think you really need a stuct there, and NOT an array) Best regards, Lucian __________________
Please read these Guidelines before posting on the forum "A person who never made a mistake never tried anything new." Einstein |
|
#5
|
||||
|
||||
|
A few things I found playing with your code:
Quote:
This gives me this error compiling with g++ 3.4.1(cygwin special) Code:
Simply put, in order to correctly add these to the standard namespace lose the '.h'. But that will require you to add a line: CPP / C++ / C Code:
Now you have access to the things (in this case cin, cout and endl) from iostream. If you leave out the 'using namespace std;' you should get those named as undeclared. If you don't, turn on some additional warnings from your compiler. For me, when I want to go hog wild, it is -Wall. Then you get some reading when compiling. Apparently your compiler doesn't care about this one but mine does. Code:
Pretty easy fix to bring you into the '90's (maybe earlier even). CPP / C++ / C Code:
Ok, next victim: Quote:
Could this be the root of this: CPP / C++ / C Code:
You are using high to index the array but high is not an integer it is a float. That's all I have time for this morning. Hope the info is useful. Mark EDIT: BTW, I don't see you using anything that needs #include <string>. I commented it out wilh no ill effects but since there are still existing errors I might have missed something. __________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work." --Thomas Alva Edison "Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety." --Benjamin Franklin "A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes." --Hugh Downs |
|
#6
|
||||
|
||||
|
Quote:
Indeed, but if he uses an *older* version of the compiler (lets say he compiles and builds with VC 6) he doesn't need to use the namespace. Of course, the newer headers are prefered, but sometimes one can't upgrade right away. Quote:
This doesn't have to do with the outdated compiler, but with the compiler "name". Again, with VC (.NET or earlier) void main will do. You can use the int main version too, it won't mind. Even better - freedom of choice, right? Just to bee on the safe side, I'm not arguing with your observations, only adding in ;-) Quote:
Wow, can't believe I missed that. You are perfectly right! Best regards, Lucian __________________
Please read these Guidelines before posting on the forum "A person who never made a mistake never tried anything new." Einstein |
|
#7
|
|||
|
|||
|
Wow thanks guys!! Your time in helping me is greatly appreciated
Well I rewrote my code last night and added a few functions and fixed up all my errors and every thing compiles now with no errors I am however still having problems with my high and low score storing but I am sure i am just over looking some thing simple! So by the sounds of it there is different syntax for the different versions of c++ (makes sence) I have version 6.0 I thought this was recent but I guess not eh? hehe I bet the book I am using is realy out of date then lolSo what version should I get? (in your opinions) Well here is my working code if you guys dont mind giving it a looky and mabie give me some constructive critisum(sp) I dont know anybody that can program and therefore only know what I can read on these forums and my book with know examples LOL CPP / C++ / C Code:
Thanks again for any and all help! sincerely Jon |
|
#8
|
||||
|
||||
|
Quote:
__________________
Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough. -- Pearl Williams |
|
#9
|
||||
|
||||
|
Quote:
Well, as far as I know, this isn't in the C Standard, but it is in the C++ Standard. I may be wrong, but I may be right http://homepages.tesco.net/~J.deBoyn...void-main.html. I'm not sure about the last ISO version and all. I agree that ALL compilers recognize int main, but not all do the void version. In conclusion you are perfectly right. The other version, standard or no standard, shouldn't be used. Or reccomended. Sorry. I usually have my main generated by the IDE, and it uses the version you specified. However, I don't mind or care if I see a piece of code using the void main declaration; if I get something like "main must return int" I know what it is all about. Actually, it bothers me more to see unindented pieces of code or other little things like that. Suggesting it is OK was still wrong and I apologize. Best regards, Lucian __________________
Please read these Guidelines before posting on the forum "A person who never made a mistake never tried anything new." Einstein Last edited by LuciWiz : 01-Mar-2005 at 07:57.
|
|
#10
|
||||
|
||||
|
Quote:
Oh wait, I get along well with Lucian. jheron, take note. There are many different people here using many different products to get the same end result (a working executable). Some use IDE's, some (like myself) use a simple editor and console to get there. It is my personal belief (not an implication that you have to do it this way) that working as close to the standards as you can get will be helpful as you learn. As you state in your first post, you are just trying to learn. Well, you have found a good place to do so. You don't have to follow these things that were being discussed but you may at some point move to an environment that is more strict than your current one. Having to 'unlearn' the things that used to work will just act to make it harder on yourself. I found (after finding GIDForums™) that you really do get a better response by using the standards instead of skirting them. One thing I really (really really) should have mentioned about the .h vs none with namespace is that it was not an ERROR but a WARNING. These are two different things to watch for as you compile your work. Errors must be taken care of, Warnings are things that your compiler/linker are saying, "Hey, there is something here you need to check out." Taking note of these (and perhaps asking why) will help you as you learn. END RANT. Quote:
Thank you Luci, I was just happy to get a chance to help (as opposed to reading someone else's) for a change. Now, BACK to OUR regularly scheduled program. jheron, so far so good, it compiled (after changing the void to int and adding a return 0; to the main) but there are still things to go forward with if you want. For example, when you get to your menue function, try hitting a letter instead of a number. Whoa, what happened? Since you are already using getline here is a snip of some code I had that deals with this a little differently. CPP / C++ / C Code:
NOTE: above uses <string> and clean_input() was something I was playing with a while back(search the forum if interested, it's here somewhere) and also requires the inclusion of <cctype>. For that matter, there are quite a few threads that deal with this topic, seach is your friend. If you want to take this further, I would be glad to play along. I have only been working with C++ for a short time and can always learn more. Or, just let it go and move on to something else, your call. Well, my coffee is done so I better get to work. Gonna need those snow boots today. :-) Mark __________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work." --Thomas Alva Edison "Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety." --Benjamin Franklin "A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes." --Hugh Downs |
Recent GIDBlog
Toyota - 2008 November Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Passing referance and passing pointer | Poolan | C++ Forum | 6 | 29-Oct-2004 08:18 |
| cannot convert parameter error on DrawTextA | ozzytx | MS Visual C++ / MFC Forum | 1 | 22-Sep-2004 03:45 |
| Passing VARCHAR to function | enomad | C Programming Language | 5 | 29-Apr-2004 15:32 |
| need help with passing 3 arrays into a function | tommy69 | C Programming Language | 14 | 07-Apr-2004 01:22 |
| Help on passing in arrays in functions? | nusstu | C Programming Language | 10 | 02-Apr-2004 11:42 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The