9 Replies - 4884 Views - Last Post: 26 June 2012 - 12:23 PM Rate Topic: -----

#1 loggggggs  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 25-June 12

How to start a cash register program in c++?

Posted 25 June 2012 - 07:37 PM

ok, i'm a amature at coding in c++ because i have found no class that teach it in my town and i want to learn it. I want to make a cash register script but i have no idea where to start and looking on the internet provides no help. if possible to give like a base to jump from or something to start with and kinda explain what look into so i can at least start to understand what should be included (besides tax) like the different functions and an idea on how to put them together?
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.

Is This A Good Question/Topic? 0
  • +

Replies To: How to start a cash register program in c++?

#2 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5246
  • View blog
  • Posts: 27,062
  • Joined: 10-May 07

Re: How to start a cash register program in c++?

Posted 25 June 2012 - 07:39 PM

I wrote this which I used to print receipts at computer shows years ago. It's old code, written in C, but could be used as a starting point.
Was This Post Helpful? 0
  • +
  • -

#3 Jeet.in  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 11
  • View blog
  • Posts: 304
  • Joined: 30-May 11

Re: How to start a cash register program in c++?

Posted 26 June 2012 - 01:32 AM

A very basic code of mine. Wrote just for fun to calculate our hostel bill. The code compiles without errors and works as intended and is syntactically correct, but not at all elegant or perfect syntax. You may edit it to suit your needs. Btw, it's in C but you can change the syntax accordingly.

 ------



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 :bigsmile: .

This post has been edited by Jeet.in: 26 June 2012 - 10:46 AM

Was This Post Helpful? -1
  • +
  • -

#4 jimblumberg  Icon User is online

  • member icon


Reputation: 4013
  • View blog
  • Posts: 12,393
  • Joined: 25-December 09

Re: How to start a cash register program in c++?

Posted 26 June 2012 - 09:23 AM

goto? system("title DATABASE APPLICATION 1.0"), Really? If you are going to try to post code, at least post decent code. Your code is riddled with bad programming practices and broken code:
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
Was This Post Helpful? 1
  • +
  • -

#5 Jeet.in  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 11
  • View blog
  • Posts: 304
  • Joined: 30-May 11

Re: How to start a cash register program in c++?

Posted 26 June 2012 - 10:47 AM

Thanks Jim for the correction. I just wrote the code for fun and I noted that it was incorrect and wrong. Sorry Again :( Deleted the code to avoid misconceptions. Thanks !
Was This Post Helpful? 0
  • +
  • -

#6 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7641
  • View blog
  • Posts: 12,887
  • Joined: 19-March 11

Re: How to start a cash register program in c++?

Posted 26 June 2012 - 10:50 AM

Forget about no2's code for the time being. The first problem you have to solve is - what problem are you trying to solve? "Cash register" is pretty vague. What would you like your program to do? If you can't describe it, you can't build it.

That's the first step you were looking for: specify the problem.
Was This Post Helpful? 0
  • +
  • -

#7 jimblumberg  Icon User is online

  • member icon


Reputation: 4013
  • View blog
  • Posts: 12,393
  • Joined: 25-December 09

Re: How to start a cash register program in c++?

Posted 26 June 2012 - 11:06 AM

@jeetin
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

Was This Post Helpful? 1
  • +
  • -

#8 Jeet.in  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 11
  • View blog
  • Posts: 304
  • Joined: 30-May 11

Re: How to start a cash register program in c++?

Posted 26 June 2012 - 11:16 AM

Jim a small question here. Why a character may not reach the EOF? I flipped my school text book which (obviously) doesn't say anything about it !

You link had this explanation:

Quote

The documentation for getchar is that it returns the next character available, cast to an unsigned char and then returned in an int return value.

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 :sad3: !

This post has been edited by Jeet.in: 26 June 2012 - 11:18 AM

Was This Post Helpful? 0
  • +
  • -

#9 jimblumberg  Icon User is online

  • member icon


Reputation: 4013
  • View blog
  • Posts: 12,393
  • Joined: 25-December 09

Re: How to start a cash register program in c++?

Posted 26 June 2012 - 11:59 AM

On some systems char is an unsigned value, which means that it can't hold a negative value. So on a system where char is unsigned you will not be able to detect an EOF condition, because EOF is defined to be a negative.

From the last C11 draft standard section 7.21.1

Quote

EOF
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 three types char, signed char, and unsigned char are collectively called
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

Was This Post Helpful? 2
  • +
  • -

#10 Jeet.in  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 11
  • View blog
  • Posts: 304
  • Joined: 30-May 11

Re: How to start a cash register program in c++?

Posted 26 June 2012 - 12:23 PM

Thank you so much just wrote an email to the author of my book to change/review some code where he uses this misconception to help students. Thanks again !
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1