HI am trying to make a program that evaluates and gives a response based on the users name and gender. I cannot figure out why it is giving the responses it gives. When USERSEX and BOTSEX are the same it will sometimes say that they are different. As I am new to programming, if you locate the problem I would appreciate help in English. Thanks
Hello lukecplusplus. I would like to start by saying you code is a bit of a mess atm, lol, but I did find the issue in your code non the less. In line 19, 27, 34, 41, you have BOTSEX == x. When using the double equals sign, you are not setting BOTSEX to 1 or 2, but instead actually doing a check, meaning, for example, in line 19, you are saying "Is BOTSEX equal to 2". What you want, is to have just have a single equal sign, which is how you set the variable. Here is your answer:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// line 19
// former line BOTSEX ==2;
BOTSEX = 2;
// line 27
// former line BOTSEX == rand()%2+1;
BOTSEX = rand()%2 + 1;
// line 34
// former line BOTSEX == 1;
BOTSEX = 1;
//line 41
// former line BOTSEX == 2;
BOTSEX = 2;
Thank you for the help! I fixed the lines you said and I am very grateful. I am trying to teach myself how to do all of this and your explanation was very helpful. For future reference I will leave the fixed code below. What exactly did you mean by messy code? Are there examples or webpages of messy or non messy code?