+ 1

Can someone help me?

So I'm working on a project, and it's not supposed to return anything. This is it: #include <iostream> #include <string> #include <cstdlib> using namespace std; class Main_Kagune_Type { int speed = 0; int attack = 1; int defense = 0; int kagune_break = 5; public: string rand_kagu { int k = 1 + (rand() % 2) if (k = 1){ string kagune = "ukaku" } if (k = 2){ kagune = "koukaku"

7th Jan 2017, 7:06 PM
Michael
Michael - avatar
9 Réponses
+ 2
Probably not: you post only a part of your code ^^
7th Jan 2017, 7:12 PM
visph
visph - avatar
+ 2
Well, you declare a class, but your main function ( wich is the starting point of the code ) only execute a return statement... so end normally with none output ^^ You need to instanciate your class ( provided that she's correctly written ), and read, write properties or execute methods... and output something ;) What do you expect when you write "it's not supposed to return anything" in your question? Your code return the value 0, which isn't nothing, but isn't displaying...
7th Jan 2017, 7:24 PM
visph
visph - avatar
+ 2
It should say there are still errors... You need parenthesis after the method name 'rand_kagu' ( and before the opening bracket ), semi-colon at end of lines content of your 'if' statements... That's what I can correct for you... But your code still not working, since you at least add 'string' before 'kagune' in your 'if (k==2)' statement, even it's surely not the behaviour attended ( but else the compilator break on an undeclared variable in the scope ). Anyway, the code finally compil and execute... with 'no output' only saying, because of my previous explanations ;)
7th Jan 2017, 7:44 PM
visph
visph - avatar
+ 2
This code was working ( maybe I forgot another correction ): #include <iostream> #include <string> #include <cstdlib> using namespace std; class Main_Kagune_Type { int speed = 0; int attack = 1; int defense = 0; int kagune_break = 5; public: string rand_kagu() { int k = 1 + (rand() % 2); if (k = 1){ string kagune = "ukaku"; } if (k = 2){ string kagune = "koukaku"; } }; }; int main() { Main_Kagune_Type mkt; return 0; } In main, just added declaration of an instance of your class, named 'mkt'... not necessary, I was starting with that for testing your class when I see your empty main function, before seeing syntax errors to correct ^^ ( and that I can't guess what you want do with )
7th Jan 2017, 7:56 PM
visph
visph - avatar
0
Hi Michael! I suggest you add semi-colons first to ease the clutter and then work on the return. also make sure to add a "}" to the end. Happy Coding!
7th Jan 2017, 7:13 PM
TheJaguar
0
Hold on, heres the rest: } }; }; int main() { return 0; }
7th Jan 2017, 7:15 PM
Michael
Michael - avatar
0
when I said it should return nothing, I mean it should say "No output" when someone hits the run button.
7th Jan 2017, 7:26 PM
Michael
Michael - avatar
0
So I tried to follow what you said, and it still says there's a problem on line 13... specifically about an expected } before int. There are other errors that come with it, but I can't quite remember them.
7th Jan 2017, 7:51 PM
Michael
Michael - avatar
0
Thanks for the help!
7th Jan 2017, 8:02 PM
Michael
Michael - avatar