Hi! I'm a c++ student. I use Borland 5.02 as my compiler. I have a problem with my assignment. Our teacher asked us to program something like an interface of an Automated Teller Machine (ATM). What I want to happen is for the program to ask for a confirmation to continue or exit if the PIN that the user enters does not match. When the the confirmation message appears, the program should do 3 things: 1. If the user enters 'y' or 'Y' (YES), the program will loop back at the beginning so he/she can enter the correct PIN; 2. If the user enters 'n' or 'N' (NO), the program should exit; 3. If the user enters a letter other than those 2 choices, the program will display an 'Invalid' message. The If-else-then statement that I have written doesn't seem to test the 'ans' variable when I try it with the letter 'n'. It goes directly to the next line instead of exiting the program.
Can anyone help me with this? I already tried so many different things just to fix this, but I just can't. Here's the code and thanks in advance:
//------------------------------------------------------------------------------
//This is where the problem is...
if(val!=0)
{
do{
form(5,19,75,21,YELLOW,RED);
gotoxy(6,20);
cprintf("Invalid PIN and confirmation. Would you like to try again? [y/n] ");
frame(5,19,75,21,YELLOW,RED);
Hi thanks for the response. I understand the approach that you did, firedraco. I think that'll work on my assignment. I will try that later. However, I don't know what tabbing and 'code tags' mean. Sorry, I'm not good with terminologies. Can you explain that to me? I really appreciate it...
Code Tags are the way to get your sample code to format nicely in this forum.
So if you type
[code]
int main()
{
//this does nothing:-)
return 0;
}
[/code]
it will appear as
1 2 3 4 5
int main()
{
//this does nothing:-)
return 0;
}
which is much easier for everyone to read, and hence to understand and help fix:-)
Tabbing refers to the indentation of the code - you can either use a single tab or 2-3 spaces to indent. Again, it all helps make it easy to read.
In the example above I have used 3 spaces to indent the code inside the {}.
Note that the formatter for the forum removes leading spaces unless you are within Code Tags.
If you don't do so already, it is probably a good idea to format all your code this way as you write it as it helps highlight the structure of the code, making spotting erors and making changes simpler.