I'm having a problem with my program deciding to stop responding. The program is as follows:
char * q = new char ;
char * i = new char ;
char * a = new char ;
q = new char ; i = new char ; a = new char ;
q = "What is 2 + 2?\n";
cout << q;
cin >> i;
a = "4";
if (i == a)
cout << "Correct.\n";
cout << "No, answer is " << a << ".\n";
delete q; delete i; delete a;
The program has a simple purpose: the goal is to have it be a sort of study guide. It will also be the first program I use new or delete in.
I had a similar problem awhile back when I learned the basics of normal C. I would forget the ampersand before my inputs in scanf and it would stop responding in the exact same way, but I didn't use scanf here.
I'm not certain, ut I think it's a similar problem with using new. Removing the delete command didn't fix it.
If it matters, I use the Digital Mars compiler, which is run from the command line, cmd.
EDIT: I have made a small modification so that the first 3 lines no longer make it so that memory for the strings is allocated twice, it now says this:
[CODE]char * q; char * i; char * a;[CODE]
Also, I thought it might help to mention that I don't get any errors or warnings. I don't see a problem, but there clearly is one. I don't tthink my program would just quit responding like that.