I am actually looking for help on creating two functions. I am sure there are pre defined functions out there, but would prefer to work on my own functions so I have a better understanding of how they work. I am very new at this so I could use some help.
First of all I would love to be able to backspace. so I was thinking of adding an if right after the cout << key;. something like,
if ( key = 8) //I believe 8 is the ASCII for the backspace key.
cout << "/b ";
counter=counter--;
I cant seem to get this to work though.
My second goal is to turn the string of numerical characters into actual integers. It is going to be a dice games gambleing system so i need to be able to add and subtract from the numbers. for instance, if i enter a wager of 100 and my bank holds 1000. If i win instead of getting 1000100 i want it to give me 1100. I am really kind of lost on where to go with this. I know i need to multply each key by 10 and add the next character. so something like
if (counter < STR_LEN)
num = 10*key + key;
Like I said I am really unsure where to go with this.
First, you are performing an assignment in if(key = 8), not a comparison. Use == to compare.
Second, just use cin for input, and let it do the conversions for you. ie.
1 2 3 4 5 6 7
int myMoney;
cin >> myMoney;
if(cin.fail()){
cin.clear();
cin.ignore(100, '\n'); //Keeping this example simple, not using limits.
}
The cin.fail() check is in case the user tries to input xyz into your int. When this happens, cin goes into a failure state and you have to clear the failure, and ignore the input that caused the failure.
tried the suggested change on the backspace structure, still not working. I am looking more for passing string variables for functions.something where the value entered goes from one register to another to be multipled by 10 and then brought back to the original register to be added to the new value. I am a newb but i think this is possible?