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%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;
}
Posts
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.
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?
I'm getting a single error about "invalid conversion from `int' to `char*' "
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.
I know we did it once in class.
Simply hitting 1, instead of 1 and then enter.
Ahh well, to class!
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
Edit: Huh, it doesn't start a quote tree?
So you're writing a program to simulate a MAC (atm) machine; what platform are you writing it on?
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?
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.