If you're familiar with the atoi() function (ASCII to integer), maybe you can help me.
Why doesn't this work?
When I run this, it outputs "1 or 2? " and then crashes. The console window stays open, but a popup says "filename.exe has encountered a problem and needs to close. We are sorry for the inconvenience.
If you were in the middle of something, the information you were working on might be lost.
Please tell Microsoft about this problem.
We have created an error report that you can send to us. We will tread this report as confidential and anonymous.
To see what data this error report contains, click here."
Then there are 3 buttons:
Debug, Send Error Report, and Don't Send.
Regardless of what I click, the window pops up two more times. Then, the console window closes.
Why doesn't this work?
Code:
#include <iostream>
using namespace std;
#include <cstdlib>
int main()
{
char *useoldmoneyC;
cout << "1 or 2? ";
cin >> useoldmoneyC;
cout << useoldmoneyC;
int useoldmoney = atoi(useoldmoneyC);
// above makes sure while loop below doesn't go crazy
// if a letter is entered
while (useoldmoney != '1' && useoldmoney != '2')
{
cout << "Please enter 1 to resume your game or 2 to start over: ";
cin >> useoldmoneyC;
useoldmoney = atoi(useoldmoneyC);
}
return 0;
}
If you were in the middle of something, the information you were working on might be lost.
Please tell Microsoft about this problem.
We have created an error report that you can send to us. We will tread this report as confidential and anonymous.
To see what data this error report contains, click here."
Then there are 3 buttons:
Debug, Send Error Report, and Don't Send.
Regardless of what I click, the window pops up two more times. Then, the console window closes.