You are viewing our Forum Archives. To view or take place in current topics click here.
Buggy C Program Help
Posted:
Buggy C Program HelpPosted:
Status: Offline
Joined: Oct 28, 201311Year Member
Posts: 1,048
Reputation Power: 91
So we had to make a program with a menu system that does the following things:
We got the main functions of the program down, but the menu is extremely buggy. We made an option for an Invalid selection and after you complete one task and return to the main menu, it'll say an accepted option is invalid. Also we made a sub menu for our temperature function and once you're finished with it, the program returns to the main menu but every single option brings it back to the temperature sub menu or says it's invalid. It's a lot to explain, but run it in a compiler (preferably Visual Studios or Codeblock) and you'll see the issue. What did we do wrong?
[ Register or Signin to view external links. ]
- Convert Temperature to Fahrenheit from Celsius and vice-versa
Convert base 10 number from 1 to 100 into Binary
How far can you go given user inputs
Display the roll of two die
Quit
We got the main functions of the program down, but the menu is extremely buggy. We made an option for an Invalid selection and after you complete one task and return to the main menu, it'll say an accepted option is invalid. Also we made a sub menu for our temperature function and once you're finished with it, the program returns to the main menu but every single option brings it back to the temperature sub menu or says it's invalid. It's a lot to explain, but run it in a compiler (preferably Visual Studios or Codeblock) and you'll see the issue. What did we do wrong?
[ Register or Signin to view external links. ]
#2. Posted:
Status: Offline
Joined: Dec 25, 200915Year Member
Posts: 2,314
Reputation Power: 1686
Status: Offline
Joined: Dec 25, 200915Year Member
Posts: 2,314
Reputation Power: 1686
How does this even compile on your machine? I am using gcc v4.8.4.
On line 265 and 281, you give printf arguments, but the formatted string has no format specifiers.
Also what is getch()? You use getchar() somewhere else in the code, so why mix it up?
As for the code, you're experiencing issues because of the way you have your do-while loops set up. On line 261, you get the user's selection. Then you compare it, and before the loop can actually loop, you get the user's selection again on line 303. You also perform an extra scanf on line 260 and display an unnecessary menu on line 302 and 305. First remove these calls.
You should also move line 22 and 23 within the main function's do-while loop, and remove lines 63 and 64, since you'd just be displaying the menu and getting the user's selection before the loop actually loops, again.
You try and cover the redundant calls by clearing the screen, but that might be giving you more issues than you hope if you try the other options. I'll let you figure the rest out. ;-)
Good luck.
On line 265 and 281, you give printf arguments, but the formatted string has no format specifiers.
Also what is getch()? You use getchar() somewhere else in the code, so why mix it up?
As for the code, you're experiencing issues because of the way you have your do-while loops set up. On line 261, you get the user's selection. Then you compare it, and before the loop can actually loop, you get the user's selection again on line 303. You also perform an extra scanf on line 260 and display an unnecessary menu on line 302 and 305. First remove these calls.
You should also move line 22 and 23 within the main function's do-while loop, and remove lines 63 and 64, since you'd just be displaying the menu and getting the user's selection before the loop actually loops, again.
You try and cover the redundant calls by clearing the screen, but that might be giving you more issues than you hope if you try the other options. I'll let you figure the rest out. ;-)
Good luck.
- 1useful
- 0not useful
You are viewing our Forum Archives. To view or take place in current topics click here.