C++ output error
May 26, 2010 at 4:38pm UTC
hi friends, I am doing some programming test from c++ book, about ATM machine,
i manage to complete the program but the output is not working.
i guess the main problem is on the output screen code.
so friend can you help me to fixed this prob, thanks.
1 2 3 4 5 6 7 8 9
cout<<"\nTraction type of availalble" ;
cout<<"\nO - open account" ;
cout<<"\nD - deposit" ;
cout<<"\nW - withdraw" ;
cout<<"\nB - Balance" ;
cout<<"\nX - Exit" ;
cout<<"\nEnter choice :" ;
cin>>transaction_type;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
#include<iostream>
#include<ctype.h>
using namespace std;
class current
{
int account_no;
double balance;
public :
void open_account();
void deposit();
void withdraw();
void show_balance();
};
void current::open_account()
{
cout<<"\nOpen current account...." ;
cout<<"\n Enter account number :" ;
cin>>account_no;
cout<<"\n Enter starting amount :" ;
cin>>balance;
}
void current::deposit()
{
int acct_no;
double amount;
cout<<"\nDeposit into current account..." ;
cout<<"\nEnter account number :" ;
cin>>acct_no;
if (acct_no != account_no)
{
cout<<"\n invalid account.Please try again" ;
}
else
{
cout<<"\nEnter amount to deposit : $" ;
cin>>amount;
balance =balance + amount;
cout<<"\n Your new balance is $" <<balance;
}
}
void current ::withdraw()
{
int acct_no;
double amount;
cout<<"\nWithdraw from current account..." ;
cout<<"\nEnter account number :" ;
cin>>acct_no;
if (acct_no != account_no)
{
cout<<"\n invalid account.Please try again" ;
}
else
{
cout<<"\nEnter amount to withdraw : $" ;
cin>>amount;
if (amount > balance)
{
cout<<"\n sorry, insufficient balance" ;
}
else
{
cout<<"\nPlease take your cash" ;
balance = balance - amount;
cout<<"\n Your new balance is $" <<balance;
}
}
}
void current::show_balance()
{
int acct_no;
cout<<"\n show current account balance " ;
cout<<"\n Enter your account number :" ;
cin>>acct_no;
if (acct_no ==account_no)
cout<<"\n Your balance is S " <<balance;
else
cout<<"\n Invalid account. Please try again" ;
}
class saving
{
int account_no;
double balance;
public :
void open_account();
void deposit();
void withdraw();
void show_balance();
};
void saving::open_account()
{
cout<<"\nOpen current account...." ;
cout<<"\n Enter account number :" ;
cin>>account_no;
cout<<"\n Enter starting amount :" ;
cin>>balance;
}
void saving ::deposit()
{
int acct_no;
double amount;
cout<<"\nDeposit into saving account..." ;
cout<<"\n Saving account deposit" ;
cout<<"\nEnter account number :" ;
cin>>acct_no;
if (acct_no != account_no)
{
cout<<"\n invalid account.Please try again" ;
}
else
{
cout<<"\nEnter amount: $" ;
cin>>amount;
balance =balance + amount;
// cout<<"\n Your new balance is $"<<balance;
}
}
void saving ::withdraw()
{
int acct_no;
double amount;
cout<<"\nWithdraw from saving account..." ;
cout<<"\nEnter account number :" ;
cin>>acct_no;
if (acct_no == account_no)
{
cout<<"\nEnter amount to withdraw : $" ;
cin>>amount;
if (amount > balance)
{
cout<<"\n sorry, insufficient balance" ;
}
else
{
cout<<"\nPlease take your cash" ;
balance = balance - amount;
cout<<"\n Your new balance is $" <<balance;
}
}
}
void saving ::show_balance()
{
int acct_no;
cout<<"\n show Saving account balance " ;
cout<<"\n Enter your account number :" ;
cin>>acct_no;
if (acct_no ==account_no)
cout<<"\n Your balance is S " <<balance;
else
cout<<"\n Invalid account. Please try again" ;
}
void main()
{
current cur;
saving sav;
char transaction_type;
char act_type;
cout<<"welcome to UniBank :" ;
for (;;)
{
while (1)
{
cout<<"\nTraction type of availalble" ;
cout<<"\nO - open account" ;
cout<<"\nD - deposit" ;
cout<<"\nW - withdraw" ;
cout<<"\nB - Balance" ;
cout<<"\nX - Exit" ;
cout<<"\nEnter choice :" ;
cin>>transaction_type;
// transaction_type = toupper(transaction_type);
if (transaction_type = 'X' )
return ;
if (transaction_type = 'O' || 'D' || 'W' || 'B' )
break ;
else
cout<<"\n Invalid type. Please try again" ;
}
while (1)
{
cout<<"\n\n Account types availalble" ;
cout<<"\nC - Current" ;
cout<<"\nS - Saving" ;
cout<<"\nX - Exit" ;
cout<<"Please enter account type :" ;
cin>> act_type;
act_type = toupper(act_type);
if (act_type =='X' )
return ;
if (act_type =='C' || 'S' )
break ;
else
cout<<"\n Invalid type.please try again" ;
}
switch (transaction_type)
{
case 'O' :
if (act_type == 'C' )
cur.open_account();
else
sav.open_account();
break ;
case 'D' :
if (act_type == 'C' )
cur.deposit();
else
sav.deposit();
break ;
case 'W' :
if (act_type =='C' )
cur.withdraw();
else
sav.withdraw();
break ;
case 'B' :
if (act_type == 'C' )
cur.show_balance();
else
sav.show_balance();
break ;
case 'X' : break ;
default :
cout<<"\n Invalid type." ;
cout<<"Please try again" ;
}
cout<<endl;
}
}
Last edited on May 26, 2010 at 4:45pm UTC
May 26, 2010 at 4:40pm UTC
Topic archived. No new replies allowed.