How to start a cash register program in c++?
Page 1 of 19 Replies - 1962 Views - Last Post: 26 June 2012 - 12:23 PM
#1
How to start a cash register program in c++?
Posted 25 June 2012 - 07:37 PM
I hope im not being annoying or seem like i'm begging to have the code given to me, i just need something to go off from so i can create it and this isn't homework its just to see if i can do it by myself.
Replies To: How to start a cash register program in c++?
#3
Re: How to start a cash register program in c++?
Posted 26 June 2012 - 01:32 AM
------
P.S. It's generally not recommended to show code here in DIC, but no2pencil showed you an excellent example so I thought I would show my one too
This post has been edited by Jeet.in: 26 June 2012 - 10:46 AM
#4
Re: How to start a cash register program in c++?
Posted 26 June 2012 - 09:23 AM
char fd;
while((fd=getc(ptr))!=EOF){
Since fd is a character, you may or may not be able to detect EOF. You may want to read this.
Jim
#5
Re: How to start a cash register program in c++?
Posted 26 June 2012 - 10:47 AM
#6
Re: How to start a cash register program in c++?
Posted 26 June 2012 - 10:50 AM
That's the first step you were looking for: specify the problem.
#7
Re: How to start a cash register program in c++?
Posted 26 June 2012 - 11:06 AM
Please don't remove content from your posts. This ruins the continuity of the discussion.
Jim
This post has been edited by jimblumberg: 26 June 2012 - 11:08 AM
#8
Re: How to start a cash register program in c++?
Posted 26 June 2012 - 11:16 AM
You link had this explanation:
Quote
The reason for this, is to make sure that all valid characters are returned as positive values and won't ever compare as equal to EOF, a macro which evaluates to a negative integer value.
If you put the return value of getchar into a char, then depending on whether your implementation's char is signed or unsigned you may get spurious detection of EOF, or you may never detect EOF even when you should.
Signaling EOF to the C library typically happens automatically when redirecting the input of a program from a file or a piped process. To do it interactively depends on your terminal and shell, but typically on unix it's achieved with Ctrl-D and on windows Ctrl-Z on a line by itself.
but I am still confused. Help !
Deleted the code to avoid -ve reps from other users
This post has been edited by Jeet.in: 26 June 2012 - 11:18 AM
#9
Re: How to start a cash register program in c++?
Posted 26 June 2012 - 11:59 AM
From the last C11 draft standard section 7.21.1
Quote
which expands to an integer constant expression, with type int and a negative value, that
is returned by several functions to indicate end-of-file, that is, no more input from a
stream;
And from a few other locations of the same standard:
Quote
the character types. The implementation shall define char to have the same range,
representation, and behavior as either signed char or unsigned char.45)
45) CHAR_MIN, defined in <limits.h>, will have one of the values 0 or SCHAR_MIN, and this can be
used to distinguish the two options. Irrespective of the choice made, char is a separate type from the
other two and is not compatible with either.
The header <ctype.h> declares several functions useful for classifying and mapping
characters.198) In all cases the argument is an int, the value of which shall be
representable as an unsigned char or shall equal the value of the macro EOF. If the
argument has any other value, the behavior is undefined.
Also note that the standard does not say what the value of EOF is, except that it is negative. So you should also never assume that EOF is negative 1, it could be -1400 which is a valid negative int, but not a valid signed char.
Jim
This post has been edited by jimblumberg: 26 June 2012 - 12:00 PM
#10
Re: How to start a cash register program in c++?
Posted 26 June 2012 - 12:23 PM
|
|

New Topic/Question
Reply



MultiQuote




|