- Apr 28, 2006
- 4,257
- 0
- 0
I am in an intro CSE class for C++, and this weeks lab assignment (which has already been submitted) was to develop a basic program that could determine whether a number input from the user was pos/neg or a 5-mult/not.
The theme was if and if/else statements which I understand and did. However, one part of my code bothered me by producing a strange output. It was not part of the assignment to test for this specific bug, but I want to know how to fix it.
In testing, when I input a value such as #@^&((@*! the cout statement would always be: "The integer value entered is negative and a multiple of five." (See code attached for context.) However, all of those symbols are of the char data type, and although chars have an equivalent integer value, I specifically defined the input to only accept int type data.
It also seems to disregard char symbols mixed with integers (125!!%!125). The program will return inconsistent result with such inputs, even though I set a condition that would send an ERROR message if non-int types were input.
Edit: The code looks sloppy, but I can't get it to stay organized like in VS.
Edit 2: Can't get it to look proper with ATF formatting. Here is a link to download the small .cpp file. If anyone remembers that website were users can copy/paste text to a server for public viewing, let me know.
The theme was if and if/else statements which I understand and did. However, one part of my code bothered me by producing a strange output. It was not part of the assignment to test for this specific bug, but I want to know how to fix it.
In testing, when I input a value such as #@^&((@*! the cout statement would always be: "The integer value entered is negative and a multiple of five." (See code attached for context.) However, all of those symbols are of the char data type, and although chars have an equivalent integer value, I specifically defined the input to only accept int type data.
It also seems to disregard char symbols mixed with integers (125!!%!125). The program will return inconsistent result with such inputs, even though I set a condition that would send an ERROR message if non-int types were input.
Edit: The code looks sloppy, but I can't get it to stay organized like in VS.
Edit 2: Can't get it to look proper with ATF formatting. Here is a link to download the small .cpp file. If anyone remembers that website were users can copy/paste text to a server for public viewing, let me know.