Chat
Micro Mart Forum
Home       Members    Calendar    Who's On
Welcome Guest ( Login | Register )
        



C++ help Expand / Collapse
Author
Message
Posted 24/11/2008 20:13:57


Pentium

PentiumPentiumPentiumPentiumPentium

Group: Forum Members
Last Login: Today @ 17:24:57
Posts: 3,012, Visits: 6,153
hey all i am building a program for uni work and its nearly done

but (there's always a but ) i have a slight problem

the program reads user input (char) and based on this moves around a maze, the problem is if the user enters a string of chars before pressing enter it reads them one by one so if i input esees

the maze then runs through the rooms by going east south east east south


what i want is a way for the program to accept input as soon as the user enters a single char any ideas?

-------------------------------------------------------------------
www.alex3410.com <- updated take a look (29/10/08)
CPU: core2duo E4300 1.8GHz (@2.6GHz), RAM: 2GB corsair XMS2, Gcard: Geforce 7900GS 256MB, Mboard:ASROCK4CoreDual-SATA2, HDD: 1 X 500GB 2X250GB, Monitor:19" acer widescreen


Post #322512
Posted 25/11/2008 07:23:12
386

386386386386386

Group: Forum Members
Last Login: Today @ 11:35:47
Posts: 583, Visits: 1,435
Look up kbhit() -- sets flag if a key has been pressed
getch() -- gets ascii value of key that has been hit.
Think about using the combo in a loop.
Post #322564
Posted 25/11/2008 12:27:35


Pentium

PentiumPentiumPentiumPentiumPentium

Group: Forum Members
Last Login: Today @ 17:24:57
Posts: 3,012, Visits: 6,153
thank you will look into them

-------------------------------------------------------------------
www.alex3410.com <- updated take a look (29/10/08)
CPU: core2duo E4300 1.8GHz (@2.6GHz), RAM: 2GB corsair XMS2, Gcard: Geforce 7900GS 256MB, Mboard:ASROCK4CoreDual-SATA2, HDD: 1 X 500GB 2X250GB, Monitor:19" acer widescreen


Post #322594
Posted 26/11/2008 12:15:10


Pentium

PentiumPentiumPentiumPentiumPentium

Group: Forum Members
Last Login: Today @ 17:24:57
Posts: 3,012, Visits: 6,153
i found a more elegant solution to the problem and just thought it might be useful for others

instead of trying to only let them enter a single char i let them enter what they want and read the first char then clear the input buffer removing the rest of the word

cin.clear();
cin.ignore( std::numeric_limits<
streamsize>::max(), '' );


that way they can enter
e,E,East & east and all 4 will cause east to be selected

-------------------------------------------------------------------
www.alex3410.com <- updated take a look (29/10/08)
CPU: core2duo E4300 1.8GHz (@2.6GHz), RAM: 2GB corsair XMS2, Gcard: Geforce 7900GS 256MB, Mboard:ASROCK4CoreDual-SATA2, HDD: 1 X 500GB 2X250GB, Monitor:19" acer widescreen


Post #322740
Posted 26/11/2008 20:59:48
386

386386386386386

Group: Forum Members
Last Login: Today @ 11:35:47
Posts: 583, Visits: 1,435
Glad to see you are thinking out of the box, and that you are not happy to be spoon-fed - what happens when they press 4 or $ or CTRL e by mistake, instead of e or E?

Sure as little eggs, users will do whatever you least expect -- sometimes I get confused on what is in standard C as compared to C++ but I'm sure you can TRY to find out how to handle exceptional cases

(EDIT - just realised what a weird expression I've used, whatever have little eggs got to do with it? Sometimes I wonder where these expressions come from -- alien influences!)
Post #322861
Posted 26/11/2008 21:13:35


Pentium

PentiumPentiumPentiumPentiumPentium

Group: Forum Members
Last Login: Today @ 17:24:57
Posts: 3,012, Visits: 6,153
lol

that's covered a switch statement that has entries for n,N,e,E etc then a default one which will catch everything else like "|?@{}45:;" etc then outputs message saying please enter a valid input

and you should see some of my programs they tend to be way outside the box lol thanks for your suggestions though they got me thinking

and i don't like spoon feeding as it does not mean you learn anything and i refuse to help others at uni if thats what they want.

but if they have thought through it and ask a question about technical stuff (like C++ input or how to use a case statement) then its ok its when they say oh can you write this bit for me etc which bugs me


This assignment has been the worst so far as i spent hours working out how to build it (i mean hours ) from scratch to a working program, but then because some people are having problems with it the teacher handed out a design for the program so all the others need to do is code it from the deign.

They don't need to sit down and work out how and why the program works + the fact i spend hours doing it and him handing that out has brought everyone else up to where i am at a fraction of the time and effort

that's on top of doing JAVA all last year then changing to C++ for the assignment and first semester then we are back to JAVA this week

/ of rant

-------------------------------------------------------------------
www.alex3410.com <- updated take a look (29/10/08)
CPU: core2duo E4300 1.8GHz (@2.6GHz), RAM: 2GB corsair XMS2, Gcard: Geforce 7900GS 256MB, Mboard:ASROCK4CoreDual-SATA2, HDD: 1 X 500GB 2X250GB, Monitor:19" acer widescreen


Post #322862
Posted 27/11/2008 11:24:26
386

386386386386386

Group: Forum Members
Last Login: Today @ 11:35:47
Posts: 583, Visits: 1,435
They don't need to sit down and work out how and why the program works [Angry] + the fact i spend hours doing it and him handing that out has brought everyone else up to where i am at a fraction of the time and effort [Angry]

Don't let it bug you - they will ever remain carp programmers. I haven't yet met a programmer who managed to learn without doing! Mind you, I do share your anger at the lecturer for spoon feeding his group, obviously he is yet another one suffering under badly crafted metrics. Probably gets a pay cut if he can't tick the box to say students understand input streams.
Post #322938
Posted 27/11/2008 13:57:59


Pentium

PentiumPentiumPentiumPentiumPentium

Group: Forum Members
Last Login: Today @ 16:58:03
Posts: 5,534, Visits: 29,218
alex3410 (26/11/2008)
that's on top of doing JAVA all last year then changing to C++ for the assignment and first semester then we are back to JAVA this week


My god has JAVA invaded schools too man i feel for you.

GO and explain carefully to your teacher that he/she is supposed to be sohwing you the delights of programming and encourage people to take it further. Not scare you too oblivion

Drop JAVA - do some C++ and learn some proper programming with Python

*yay*

(btw really do avoid Java like the plague if you want to be a good programmer. I neve3r touched it as a self taught programmer: from PHP -> perl -> python -> AMS/C/++ in that order. Some of my peers aregraduate Comuter Science majors trained on Java: and they dont have a clue. We interviewed 2 new programmers the other day and as part of the interview got them to put together a simple stats simulation in C or C++. They struggled like hell. So I let them try JAVA and they still couldnt manage it.

Bear in mind this was a problem I myself solved in Python at the age of 20...... (and I am crap at the maths!)...

They said C++ was not "clever" enough to do it and that Java did not have the libraries........ (it is and it does)..

Cheers,
Tom
My Crime is that of curiosity, my crime is that of outsmarting you




Post #322959
« Prev Topic | Next Topic »


Reading This Topic Expand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: TheEditor, admin, Sarah of the Dead

Permissions Expand / Collapse