More C++ Help

Mmmm... Cocks...Mmmm... Cocks... Registered User regular
edited February 2007 in Help / Advice Forum
Hey, I dunno if you guys remember my last thread on C++ but I was a mess.


Here's what I have so far. Were making a little MAC machine program. The whole thing went together smoothly and I couldn't be more happy. Except, well, on the input part where they select their transaction type I know there's a way to get it so once they press a 1 or 2 etc. it does that instead of waiting for the Enter key. Something like CharGet? Or something?
I can't find anyting on it online or in my notes.
#include <iostream>
 
using namespace std;
 
 
int main()
{
     int correctpin;
     int pin;
     int selection;
     int amount;
     
correctpin=6083;

cout<<"Please enter you PIN number";
cin>>pin;

if(pin==correctpin)
{
cout<<"PIN accepted, enter your transaction type";
cout << endl; 


cout<<"1.Deposit ";
cout << endl; 


cout<<"2.Withdraw";
cout << endl; 


cout<<"3.Exit";
cout << endl; 
cin>>selection;

              if(selection==1 or selection==2)
                            {
                             cout<<"Enter amount in multiples of 5" << endl;
                             cin>>amount;
                                           if(amount&#37;5==0)
                                           {
                                           cout<<"Thank you, please remove your cash"  << endl;
                                           }
                                           
                                           else
                                           {
                                           cout<<"Invalid amount, please remove your card" << endl;
                                           }
                             }
                                        
             
}
else cout<<"Incorrect PIN" <<endl;
                   
 
 
     system("PAUSE");
     return EXIT_SUCCESS;
}

Mmmm... Cocks... on

Posts

  • AndorienAndorien Registered User regular
    edited February 2007
    cin.get(selection, 1);
    

    I believe that should do it. First parameter is the variable in which it'll be stored, second parameters is the number of characters to accept.

    Andorien on
  • Mmmm... Cocks...Mmmm... Cocks... Registered User regular
    edited February 2007
    Huh, but where do I drop this?

    I don't think that's the one we the one time but if I get it to work that's good as gravy.


    Like here in this little chunk?
    
    cout<<"3.Exit";
    cout << endl; 
    cin.get(selection, 1);
    
                  if(selection==1 or selection==2)
    

    I'm getting a single error about "invalid conversion from `int' to `char*' "

    Mmmm... Cocks... on
  • SmasherSmasher Starting to get dizzy Registered User regular
    edited February 2007
    There is no standard way to do this in c++. Different platforms will have different ways to accomplish it, but I don't know how you'd go about it on a MAC machine.

    cin.get will retrieve one character from the buffer, but there has to be something in the buffer, and in standard c++ the only way to get it into there is to hit the enter key.

    Smasher on
  • AndorienAndorien Registered User regular
    edited February 2007
    Ahh, I thought that would do it, guess not. Truth be told, I haven't had a situation where I've made a C++ program do this. Easy as hell in Assembly.

    Andorien on
  • Mmmm... Cocks...Mmmm... Cocks... Registered User regular
    edited February 2007
    No, hmm, maybe I'm simply asking you guys the wrong way.

    I know we did it once in class.

    Simply hitting 1, instead of 1 and then enter.


    Ahh well, to class!

    Mmmm... Cocks... on
  • SmasherSmasher Starting to get dizzy Registered User regular
    edited February 2007
    No, hmm, maybe I'm simply asking you guys the wrong way.

    I know we did it once in class.

    Simply hitting 1, instead of 1 and then enter.


    Ahh well, to class!
    There are ways to do it on specific platforms. They're different on most platforms though, and rely on importing system specific header files. If you were working with Windows/Unix it'd be easy to google, but a quick search for MAC machines didn't turn up anything.

    http://www.thescripts.com/forum/thread135882.html
    http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.17
    http://www.cprogramming.com/faq/cgi-bin/smartfaq.cgi?answer=1045691686&id=1043284392

    Smasher on
  • stiliststilist Registered User regular
    edited February 2007
    Smasher wrote:
    There are ways to do it on specific platforms. They're different on most platforms though, and rely on importing system specific header files. If you were working with Windows/Unix it'd be easy to google, but a quick search for MAC machines didn't turn up anything.
    I believe you may have misunderstood; my impression is that the project is to simulate a MAC, rather than write a program for it.

    stilist on
    I poop things on my site and twitter
  • Mmmm... Cocks...Mmmm... Cocks... Registered User regular
    edited February 2007
    stilist wrote: »
    I believe you may have misunderstood; my impression is that the project is to simulate a MAC, rather than write a program for it.
    Heh, yea, MAC machine as in an ATM. If you look at the program you can see Deposits and Withdraws and so on.

    Edit: Huh, it doesn't start a quote tree?

    Mmmm... Cocks... on
  • SmasherSmasher Starting to get dizzy Registered User regular
    edited February 2007
    Quotes are automatically trimmed now; it'll probably be fixed soon.

    So you're writing a program to simulate a MAC (atm) machine; what platform are you writing it on?

    Smasher on
  • Bob SappBob Sapp Registered User regular
    edited February 2007
    Probably used the non-standard getch() or getche() function.

    Bob Sapp on
    fizzatar.jpg
  • Mmmm... Cocks...Mmmm... Cocks... Registered User regular
    edited February 2007
    Smasher wrote: »
    Quotes are automatically trimmed now; it'll probably be fixed soon.

    So you're writing a program to simulate a MAC (atm) machine; what platform are you writing it on?
    Do you mean what compiler or OS or what?

    Anyway the teacher went over something real fast on cin.get saying it wouldn't work in ours for some undeclared reason. I meant to get ask him more about it but in a three hour class you tend to forget what you wanted to do after class.

    My last post was actually made during a brief break when the teacher ran out of the room. I guess my problem is no longer a problem, so.. thread over?

    Mmmm... Cocks... on
  • nethneth Registered User regular
    edited February 2007
    as a note, i like www.cppreference.com as a good place to look for standard functions.

    The one i would use is get() so in place of your cin<<selection part. so use
    char ch;
    cin.get(ch)

    there. however, this function reads a char where you want an int, so you have to do
    selection = atoi(ch);
    right afterwards.

    atoi() is a string to integer function (think alpha to integer) that is useful.


    [edit] well shit, i didn't read your last post saying it wouldn't work, odd.

    neth on
Sign In or Register to comment.