| Yasar (16) | |||||
|
hello , i have started to do the beginners excercises , also if any1 could tell me if any of my codes are going wrong in any place it is much appreciated :) here is what i came up with when doing the grading programme :
in regards to your question Moschops i think this code should surfice however i cant seem to get somthing that isnt a number to work but it works for unwanted numbers :
a hint as to the direction of screening out non-numbers can be helpful | |||||
|
Last edited on
|
|||||
| Moschops (5959) | |
((grade>=90)You've got an extra ( there.To make it more advanced, what happens if someone enters a number greater than 100, or a negative number, or they enter something that isn't a number at all? Can you write code to handle that situation? | |
|
|
|
| Yasar (16) | |||||
i also have done the beverages excercise the if else style :
i have also done it in a switch statement style :
| |||||
|
Last edited on
|
|||||
| Yasar (16) | |||||||
here is the first part of while excercise :
the 2nd task :
here is the third task :
| |||||||
|
Last edited on
|
|||||||
| fg109 (131) | |
| I started doing them two days ago. I'm having real trouble with the tic-tac-toe exercise. Can't figure out how to know when the player is about to win and have the computer block him/her without listing every winning combination. | |
|
|
|
| Yasar (16) | |||
here is the 1st task of the Pancack excercise :
like this ? , i dont know why i didnt do that in the first place lol | |||
|
Last edited on
|
|||
| Bazzy (6281) | |
| You should use a loop instead of all these cin/cout in the last program | |
|
|
|
| Archimaredes (38) | |
| Where exactly are these beginner exercises? | |
|
|
|
| TheIdeasMan (1564) | |
|
Hi all, Here are some things I have noticed: Switch statements are much better than a long list of else if's, as long as the case expressions are constant ( which is the case here - the beverages program). The grades program relies on the order of the else if statements, the program could be broken if this is messed up somehow - can you think of a better way to do it? Hint: You might need to do two tests to determine the grade ( although these can both be done in 1 line of code). TheIdeasMan | |
|
Last edited on
|
|
| fg109 (131) | |||||
|
Beginner Exercises: http://www.cplusplus.com/forum/articles/12974/ The beverages program can be even shorter if a string array was used. Then there would be no need for any selection structures. And for the grade program, I guess you can say it would be broken if the user enters a negative number. I have mine as a switch statement because I divide the inputted score by 10 (which leaves me an integer from 0 to 10). This is my code for the guessing game:
And this is my code for the tic-tac-toe game:
I haven't finished the dungeon crawl game yet. I think I will need to learn to create and use classes first. | |||||
|
Last edited on
|
|||||
| fg109 (131) | |||
|
I've spent the past two hours working on the dungeon crawler game, but there is a bug that I can't figure out. The program doesn't respond to player control correctly. For example, I tell it to go right, but it goes up. I tell it to up, and it goes to the lower right. But sometimes it works correctly. I have no idea which part of my code is responsible for it. Below is all of the code for the program. The lines relevant to player input is 120 to 151. EDIT: I figured it out... I didn't initialize the a and b variables in the function that controls the player. That meant it worked fine when I was moving diagonally, because I was setting both their values since I was moving in two axes. But when I was moving in a single axis, I was only setting one variable and ignoring the other one, which means it had random garbage and led to unpredictable movement.
| |||
|
Last edited on
|
|||
| TheIdeasMan (1564) | |||
Dividing by 10 might seem aggod idea, but what if things change in the future? Imagine the school wants to give addittional grades like A+,A-, B+, B-, C+,C-. Dividing by 20 now, and the code is tarting to be messy. So, see if you can work out a better way given my clue in an earlier post.
TheIdeasMan | |||
|
|
|||
| Yasar (16) | |||
here is the 2nd task for the pancake excercise i had to find the min value as well as max :
the min algorith seems sound to me however i cannot get it to work any pointers as to what is going wrong would be appreciated :) | |||
|
|
|||
| Yasar (16) | |||||
|
i have done the first task for the bracket search excercise if u see anything that i can improve upon let me know :)
for the second task here is the source code :
| |||||
|
Last edited on
|
|||||
| fg109 (131) | |
For your pancake problem, I'm assuming that you have a #define PAN 10 somewhere.What you did first was to declare an array called Number_Eaten that contains 10 elements. This means the array has elements Number_Eaten[0], Number_Eaten[1], ... , Number_Eaten[9]. Then in your main function, you set max and min to Number_Eaten[10] which doesn't exist. | |
|
|
|
| Yasar (16) | |||||||
yh i picked up on that but i cant seem to set it to start from the begining of an array , you see what i did was set an element of array i.e
than with the loop after each iteration the user enters a number of pancakes they have eaten which is stored in the array Number_Eaten[PAN]i have also tried placing the max and min like this :
but no luck here is full code any advice is helpfull and fg109 thnx for yor reply:
| |||||||
|
Last edited on
|
|||||||
| fg109 (131) | |
|
When you assign values for max and min, you haven't input any values into your array yet. I'm not sure whether Number_Eaten[0] is 0 or some random garbage at that point. Either way, it will mess up your program. What you can do is ask for and take input for Person1 outside of the loop, then initialize your max/min variables to Person1, and enter the loop afterwards. You could also just try initializing max to 0 and min to 99999, and change the if-else-if to two ifs instead. But depending on what values are input, that might not work so well. | |
|
|
|
| Yasar (16) | |||
yup it is working now here is the code :
| |||
|
Last edited on
|
|||
| fg109 (131) | |
| Since you've taken the 1st person out of the loop, you should start the loop with i = 1. | |
|
|
|
| Yasar (16) | |||
since i forgot to add peoples names in i did that just now :
| |||
|
|
|||