Discuss about Programming here. You may release your source, post guide and even ask questions!
Moderator: wizme
Ladylove
Dark Lord
Posts: 121 Joined: Wed Sep 02, 2009 10:38 pm
Post
by Ladylove » Fri Feb 25, 2011 7:31 pm
hello, i still new in c++. my tuisyen teacher want me to solve this problem. can someone teach me how to get the password to access this program.
p/s : i've try 123456 , and its not the password. =='
Code: Select all
/*
***Automated Teller Machine with authentication routine***
*/
#include<iostream.h>
int main()
{
int password;
for (int i=0;i<3;i++)
{cout <<"enter password:\n";
cin>>password;
if (password==123456)
{cout<<"korek!!!\n";
double balance = 10000;
double withdraw, deposit;
int option;
cout<<"\n";
cout<<" ***MOGOL***\n";
cout<<"*** Automated Teller Machine***"<<endl;
cout<<"Choose a Transaction:\n";
cout<<"\n";
cout<<"[1] Inquire Balance \n"
<<"[2] Withdraw \n"
<<"[3] Deposit \n"
<<"[4] Quit \n"
<<"\n"
<<"Enter Option:";
cin>>option;
switch(option)
{
case 1:
cout<<"\n[[[BALANCE INQUIRY]]]\n";
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<"\n Your current balance is $"<<balance<<endl;
break;
case 2:
cout<<"\n[[[WITHDRAW]]]\n";
cout<<"Enter amount: $";
cin>>withdraw;
balance = balance - withdraw;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<"You withdrew $"<<withdraw<<endl;
cout<<"Your remaining balance is $"<<balance<<endl;
continue;
case 3:
cout<<"\n[[[DEPOSIT]]]\n";
cout<<"Enter amount: $";
cin>>deposit;
balance = balance + deposit;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<"You deposited $"<<deposit<<endl;
cout<<"Your new balance is $"<<balance<<endl;
continue;
case 4:
cout<<"\n***[[[EXIT MODE]]]***\n";
break;
default:
cout<<"\n That is an invalid option \n";
}
break;
}
else
cout<<"Pls try again!!!\n";}
return 0;
}//
happy125
Headmaster of Darkness
Posts: 549 Joined: Tue Jun 22, 2010 10:06 pm
Location: Singapore
Post
by happy125 » Fri Feb 25, 2011 8:12 pm
wad u mean try to find password? isnt it 123456? wad kind of error u occur?
most impt thing u forgot
lots of semi colon u forgot too. whoever gave u this script doesnt deserve to be a teacher lol. so many mistakes
Ladylove
Dark Lord
Posts: 121 Joined: Wed Sep 02, 2009 10:38 pm
Post
by Ladylove » Fri Feb 25, 2011 9:25 pm
actually , he is not really a real tuisyen teacher. i mean he is a friend of mine. :DD he teach me C++ , so i must respect him marr. he copy that from a random post in internet. ==' btw , i already get into that ATM machine program. i deleted some part of it. im still new in c++ baa. hehe.
happy125
Headmaster of Darkness
Posts: 549 Joined: Tue Jun 22, 2010 10:06 pm
Location: Singapore
Post
by happy125 » Fri Feb 25, 2011 9:50 pm
i would say the code fails around once every 2 lines. i corrected abit and got lazy heres the corrected one. and wads a tuisyen
Code: Select all
/*
***Automated Teller Machine with authentication routine***
*/
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int password;
double balance = 10000;
double withdraw, deposit;
int option,i,tries=3;
for (i=0;i<=3;i++)
{
cout <<"Enter password: ";
cin>>password;
if (password==123456)
{
cout<<"korek!!!\n";
break;
}
else
{
tries--;
cout<<"\nWrong password. "<<tries<<" tries left.\n\n";
if(tries==0)
{
exit(0);
}
}
}
cout<<"\n";
cout<<" ***MOGOL***\n";
cout<<"*** Automated Teller Machine***"<<endl;
cout<<"Choose a Transaction:\n";
cout<<"\n";
cout<<"[1] Inquire Balance \n";
cout<<"[2] Withdraw \n";
cout<<"[3] Deposit \n";
cout<<"[4] Quit \n";
cout<<"\n";
cout<<"Enter Option:";
cin>>option;
switch(option)
{
case 1:
cout<<"\n[[[BALANCE INQUIRY]]]\n";
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<"\n Your current balance is $"<<balance<<endl;
break;
case 2:
cout<<"\n[[[WITHDRAW]]]\n";
cout<<"Enter amount: $";
cin>>withdraw;
balance = balance - withdraw;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<"You withdrew $"<<withdraw<<endl;
cout<<"Your remaining balance is $"<<balance<<endl;
break;
case 3:
cout<<"\n[[[DEPOSIT]]]\n";
cout<<"Enter amount: $";
cin>>deposit;
balance = balance + deposit;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<"You deposited $"<<deposit<<endl;
cout<<"Your new balance is $"<<balance<<endl;
break;
case 4:
cout<<"\n***[[[EXIT MODE]]]***\n";
break;
default:
cout<<"\n That is an invalid option \n";
}
return 0;
}
done the password thing for u. look at it. the switch case thing i lazy liao u do urself.