Challenge 2 problem!
Post a Reply
|Oldest Newest Rating|
· January 31, 2015
You're right! Thank you so much!
· January 29, 2015
1) Well the correct format of your scanf("%c", ready) would be
Do you get the point. Why create a string and take computer memory just to check something and the input only 1 character . You can create a character type (ot string) and pass it on to it. Even better option is to use just getchar(); So just replace it with and remove that string ready as it isn't needed. Also if you are making app for windows just use system("pause"); but don't forget to include #include <stdlib.h> With this method you can even remove text Press any key to continue as this function will do it automatically.
2) Yes that is tru. But in this case you are passing a string in to a character type and that is wrong.
char pogadjanje; // single character value
scanf("%s", &pogadjanje); // %s that is a string type
There are 2 solutions:
Ok now about reducing the number of variables:
So you just need 3 dice variables, I leave you to figure out why. You can even remove all dice variables but try to do it by your self.
· January 29, 2015
I kinda knew the problems with switch statmens I just had to change the <,>....and that 1) if you mean about scanf("%c", ready) its just for checking if the user is ready and if he is to press any key to continue...2) isn't string an array of characters?.........
and about the variables could you please tell me which ones are unnecessary?
and I implemented srand, didn't know about this function that was the main problem I was always getting same numbers and didn't know what was causing that problem...
and I'll do the thing with giving the user few chances... thanks for advices!
· January 28, 2015
The problem was in the If in the switch. If user's input is H they think next sum of dices will bi bigger than the first one. So the test should be
and if they input L they think that the next sum of dices will be lower than the first one.
Also their are few others problems in your code, compiler is able to work over them but that isn't good for your code.
1)You are declaring a string and then filling it with 1 character on unsigned place.
2) You are scanning string type in character variable.
There are also some thing to make your code more smaller and more efficient, and be more functional.
Try to reduce the number of variables.
Implement srand so the program doesn't give same results.
Give user option to make mistake. If your input doesn't fulfills the requirements (L or S or H) give him another chance don't end the program.
Remove the libraries that you aren't using.
If you have hard time with anything let me know and I will try to help.
One of the most popular languages of all time.
|Bucky Roberts Administrator|