|
| pressence (18) | |||
Hello, I posted a while ago to get some help with a simple game that I was creating to test what I had learned. I decided to rewrite the code to add new things that I've learned. I'm getting a lot of errors, I'm sure it has something to do witht he function, but if you could look at this code, it would be greatly appreciated, thank you, and thanks to everyone that's helped me in the past!
Here are the errors: 1>c:\users\scott\desktop\jeremy\c++\programs\program test\program test\program.cpp(5) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\users\scott\desktop\jeremy\c++\programs\program test\program test\program.cpp(5) : error C2086: 'int hero_health' : redefinition 1> c:\users\scott\desktop\jeremy\c++\programs\program test\program test\program.cpp(4) : see declaration of 'hero_health' 1>c:\users\scott\desktop\jeremy\c++\programs\program test\program test\program.cpp(6) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\users\scott\desktop\jeremy\c++\programs\program test\program test\program.cpp(6) : error C2086: 'int monster_health' : redefinition 1> c:\users\scott\desktop\jeremy\c++\programs\program test\program test\program.cpp(4) : see declaration of 'monster_health' 1>c:\users\scott\desktop\jeremy\c++\programs\program test\program test\program.cpp(7) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\users\scott\desktop\jeremy\c++\programs\program test\program test\program.cpp(7) : error C2086: 'int hero_damage' : redefinition 1> c:\users\scott\desktop\jeremy\c++\programs\program test\program test\program.cpp(4) : see declaration of 'hero_damage' 1>c:\users\scott\desktop\jeremy\c++\programs\program test\program test\program.cpp(8) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\users\scott\desktop\jeremy\c++\programs\program test\program test\program.cpp(8) : error C2086: 'int monster_damage' : redefinition 1> c:\users\scott\desktop\jeremy\c++\programs\program test\program test\program.cpp(4) : see declaration of 'monster_damage' 1>c:\users\scott\desktop\jeremy\c++\programs\program test\program test\program.cpp(9) : error C2078: too many initializers 1>c:\users\scott\desktop\jeremy\c++\programs\program test\program test\program.cpp(43) : error C2143: syntax error : missing ';' before 'if' 1>c:\users\scott\desktop\jeremy\c++\programs\program test\program test\program.cpp(43) : error C2065: 'fight' : undeclared identifier 1>c:\users\scott\desktop\jeremy\c++\programs\program test\program test\program.cpp(43) : error C2146: syntax error : missing ')' before identifier 'goblin' 1>c:\users\scott\desktop\jeremy\c++\programs\program test\program test\program.cpp(43) : error C2059: syntax error : ')' 1>c:\users\scott\desktop\jeremy\c++\programs\program test\program test\program.cpp(44) : error C2065: 'goblin' : undeclared identifier 1>c:\users\scott\desktop\jeremy\c++\programs\program test\program test\program.cpp(44) : error C2143: syntax error : missing ';' before '{' 1>c:\users\scott\desktop\jeremy\c++\programs\program test\program test\program.cpp(49) : error C2064: term does not evaluate to a function taking 5 arguments 1>c:\users\scott\desktop\jeremy\c++\programs\program test\program test\program.cpp(51) : error C2181: illegal else without matching if 1>c:\users\scott\desktop\jeremy\c++\programs\program test\program test\program.cpp(59) : error C2448: 'battle' : function-style initializer appears to be a function definition 1>Build log was saved at "file://c:\Users\Scott\Desktop\Jeremy\C++\Programs\Program Test\Program Test\Debug\BuildLog.htm" 1>Program Test - 18 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== | |||
| Bazzy (3183) | |
| Lines 6-9: You can't do that outside a function. Put the = in de declaration line ( line 5 ) so the constructor are called ( not the = operator ) Line 10: You didn't specify the parameter types Line 13: string battle has the same name as the function Lines 21-38: Don't use a goto there, use a loop Line 43: Missing semicolon Line 44: Missing quotes on "fight goblin" Lines 42-55: Same as 21-38 Line 59: Missing parameter types and function return type specifiers | |
Last edited on | |
| pressence (18) | |||
okay, I've changed some of what you said. Everything but the loops, I'm not sure what loops I should use instead of a goto...I've got one error. It's saying I'm missing a type specifier.
| |||
| Bazzy (3183) | |
| Line 56. Use while loops. | |
Last edited on | |
| pressence (18) | |
| Thanks for all your help, I really appreiciate it. I'm going to look over the while loops in the book, and see if I can replace the code with those loops. there's one more problem tho. When the program is run, it returns 0 for both hero_RH (remaining health), and monster_RH (remaining health). | |
| Bazzy (3183) | |
| The battle function is messy, you are confusing global variables with function arguments and you don't need a return value. | |
| pressence (18) | |
| I wouldn't doubt it's messy. I've only been doing this for a short while. Do you have any pointers on how to tidy this up? | |
| Zhuge (324) | |
| It's not just messy, like Bazzy said some of it is wrong. Functions can only return one value, so your return is not going to work like you expect, and for some reason you have duplicates of all the global variables as function parameters. Additionally, you unconditionally set them (the local values) to set values, meaning whatever you pass in/whatever their current value, they will be changed to 100, 5, and 10. You should probably read up more on functions and variables. | |
| pressence (18) | |
| Okay, I had made this game previously to return only hero remaining health, and it worked. I wasn't sure if I could have the function return two values or not, I was just seeing if it was possible. These variables aren't meant to have any other value than 100 for hero health, and 5 for monster health, and 10 for monster damage, as this isn't a real game, but a mock game....I'll have to tweak a few things to make it simpler...I'm still just learning...thanks for the help I've recieved | |
| pressence (18) | ||
zhuge, can you explain to me what you mean about.
I know I have all the variables as global variables, does that mean that I did not need to declair them as integers in other places? I was getting errors, until I did in some other places.. | ||
Last edited on | ||
| firedraco (2048) | |
| What it means is that when you are inside a function, your function parameters (since they have the same name as the global variables), will be used *instead* of your global variables (they are different). I think you need to go look up more information on functions and how they work. | |
| pressence (18) | |||
Hey, I've got two functions in here now, to split up the work, and output the two values. The program is getting errors on it's build tho. I am just learning functions now, and I'll admit, a lot of this was expirimentation so any pointers would really help.
error C2078: too many initializers error C2146: syntax error : missing ';' before identifier 'Hbattle' term does not evaluate to a function taking 2 arguments term does not evaluate to a function taking 2 arguments function-style initializer appears to be a function definition function-style initializer appears to be a function definition | |||
| ljrobison (53) | |
| Well I can tell you line 47 needs a semi-colon at the end. =) | |
| Bazzy (3183) | |
| You have the same errors I corrected you on the first post. You should read the tutorial about functions http://www.cplusplus.com/doc/tutorial/functions/ | |
Registered users can post in this forum.
