-
September 18th, 2009, 07:34 AM
#1
basic c++ problem
i am a learning programmer still at basic C++ , i got this project and i did my work deadline is coming, i am really at lost here. can i ask some help in debugging this code i made? i might learn something from asking the right place.
#include<stdio.h>
#include<conio.h>
#define p printf
#define s scanf
#define g gotoxy
main()
{
char ch,option,exit;
float pin1,pin2,pin3,pin4,pin5;
float bal1,bal2,bal3,bal4,bal5;
float pin,amnt_deposit,amnt_wthdrw,balance;
float repeat1;
clrscr();
g(31,2);p("=======================");
g(31,3);p("= ANGELI'S ATM MACHINE =");
g(31,4);p("=======================");
g(7,23);p("GRP2: SY:2009-2010 1st Sem FINALS: ST-201 4:00-5:30 MR. M. BULAWAN");
g(35,12);p("Enter PIN");s("%f",&pin);
pin1=11111;bal1=0.00;
pin2=22222;bal2=0.00;
pin3=33333;bal3=0.00;
pin4=44444;bal4=0.00;
pin5=55555;bal5=0.00;
balance=0;
{
if (pin==1 || pin==2 || pin==3 || pin==4 || pin==5)
{
g(30,12);p("*** PIN accepted! ***");delay(100);
delay(100);
goto menu_deposit;
}
else
{
g(20,12);p("*** Invalid PIN! Please try again...***");
getch();
goto repeat1;
}
}
menu
{
clrscr();
g(28,7);p("Pick-A-Choice");
g(28,8);p("[1] Deposit");
g(28,9);p("[2] Withdraw");
g(28,10);p("[3] Balance Inquiry");
g(28,11);p("[4] Exit");
g(28,12);p("Choice: ");option=getche();
switch(option)
{
case'1':
{
menu_deposit:
clrscr();
g(34,2);p("[DEPOSIT]");
g(22,9);p("How much would you like to deposit\?");
g(22,10);p("Amount: ");s("%f",&amnt_deposit);
balance=balance+amnt_deposit;
delay(100);
delay(100);
g(22,17);p("P%.2f was added to your account.",amnt_deposit);
delay(100);
g(22,17);p("Press any key to proceed...");
getch();
goto menu;
}
case'2':
{
rewthdrw:
clrscr();
g(22,7);p("amount:P");s("%f",&amnt_wthdrw);
if(amnt_wthdrw>balance)
{
delay(100);
g(22,9);p("Sorry, but you do not have unsufficient fund in your account.");
getch();
goto rewthdrw;
}
if(amnt_wthdrw<100)
{
delay(100);
g(22,9);p("This machine does not allow withdrawal's less than P100.");
getch();
goto rewthdrw;
}
balance=balance-amnt_wthdrw;
g(22,9);p("Transaction in progress...");
delay(100);
delay(100);
delay(100);
g(22,10);p("Get your cash and transaction slip...");
delay(100);
delay(100);
delay(100);
g(22,11);p("Thank you for banking with us!");
delay(100);
g(22,15);p("Press any key to proceed...");
getch();
goto menu;
}
case'3':
{
clrscr();
g(28,2);p("[BALANCE INQUIRY]");
g(22,9);p("Transaction is in progress...");
delay(100);
delay(100);
delay(100);
g(22,11);p("Your account balance: P%.2f",balance);
g(22,13);p("Press any key to proceed...");
getch();
goto menu;
}
case'4':
{
turbo:
clrscr();
g(26,10);p("Want another Transaction?");
g(27,11);p("Enter another [P]IN");
g(27,12);p("[E]ND Transaction.");
ch=getch();
if(ch=='p'||ch=='P')
{
menu_pin:
clrscr();
{
if(pin==pin1)
{
bal1=balance;
}
if(pin==pin2);
{
bal2=balance;
}
if(pin==pin3);
{
bal3=balance;
}
if(pin==pin4)
{
bal4=balance;
}
if(pin==pin5)
{
bal5=balance;
}
}
g(30,2);p("[ENTER ANOTHER PIN]");
g(30,12);p("Enter new PIN: ");s("%f",&pin);
{
{
if(pin==pin1)
{
bal1=balance;
goto menu;
}
if(pin==pin2);
{
bal2=balance;
goto menu;
}
if(pin==pin3);
{
bal3=balance;
goto menu;
}
if(pin==pin4)
{
bal4=balance;
goto menu;
}
if(pin==pin5)
{
bal5=balance;
goto menu;
}
else
{
g(30,12);p("Invalid PIN!");
g(30,13);p("Please try again...");
getch();
goto menu_pin;
}
}
}
else if(ch=='e'||ch=='E')
{
exit_repeat;
clrscr();
g(30,10);p("Are you sure [Y/N]\?");
g(30,11);p("Choice: ");
exit_option=getch();
switch(exit_option)
{
case'Y':
case'y':
g(25,14);p("Thank you for your banking with us!");
goto exit;
case'N':
case'n':
g(25,14);p("Invalid choice. Please try again...");
getch();
goto exit_repeat;
}
}
else
{
g(26,17);p("Invalid Choice.");
g(26,18);p("Press a key to continue.");
getch();
goto turbo;
}
}
default:
g(16,16);p("Sorry, but you have entered an invalid choice!");
g(30,17);p("Please try again...");
getch();
goto menu;
}
}
exit:
getch();
return 0;
}
that's it , i know about the delay , i don,'t have #include<dos.h> but the rest of my problems still exist total i got is 7 or 5 i think , really help would be appreciated thanks.
-
September 18th, 2009, 08:42 AM
#2
Re: basic c++ problem
Originally Posted by boxofish
i am a learning programmer still at basic C++ , i got this project and i did my work deadline is coming, i am really at lost here. can i ask some help in debugging this code i made? i might learn something from asking the right place.
First, use code tags when posting code. The code you posted is practically unreadable.
Second, your code is not valid C++. The main() function returns an int, and you have not specified that main() returns a value.
Third, get rid of "goto". The last thing anyone wants to look at is code that jumps all over the place, making it difficult to follow. The usage of goto is hardly, if ever used by even the most sophisticated programs. There is no reason why you should resort to spaghetti coding using goto for such a simple program.
Third, was this compiled using Visual C++? There is no such function as "gotoxy", clrscr(), etc.
Fourth, why are you shortening the printf and scanf function names using #define macros? This, added to your use of goto, makes the program hard to understand and follow. Use the full names -- you don't make the code "slick" by shortening those names.
Regards,
Paul McKenzie
-
September 18th, 2009, 09:30 AM
#3
Re: basic c++ problem
Hi all.
Maybe I'm wrong, but I remember that #define macro replaces the symbol in code at pre-compiled time.
So the preprocessor changes the statement
Code:
balance=balance+amnt_deposit;
in
Code:
balance=balance+amnt_deprintfosit;
for example; in this case your code never will be compiled.
-
September 18th, 2009, 04:15 PM
#4
Re: basic c++ problem
davide, thats not correct. #defines only replace tokens (ie whole words), not any matching string
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|