what's the problem

#include<iostream>
#include<conio.h>
#include<sarveshfn.h> //includes fuction diff_time which difference two given time
using namespace std;
struct date
{
int day, month, year;
};
class account
{
string first_name, middle_name, last_name, address;
int mobile_no, account_no;
char type;
double balance;
date open_date;
date dep_date;
date with_date;
date max_date;
static int count;
public:
void get_detail();
void disp();
void inc_balance(double);
void dec_balance(double);
void tran_balance(double);
//void SI(double, float, float)
};
int account::count = 0;
void account::get_detail()
{
account_no = 100000 + count++;
cout<<"Enter the following details: \n";
cout<<"First Name \t:";
cin>>first_name;
cout<<"Middle Name \t:";
cin>>middle_name;
cout<<"Last Name \t:";
cin>>last_name;
cout<<"Permanent Address \t:";
cin>>address;
cout<<"Mobile number \t:";
cin>>mobile_no;
cout<<"Enter 'S' for saving a/c or 'C' for current a/c:";
cin>>type;
cout<<"Enter today's date in form of 'DD MM YY'\t:";
cin>>open_date.day>>open_date.month>>open_date.year;
max_date.day = open_date.day; max_date.month = open_date.month; max_date.year = open_date.year;
cout<<"Opening Balance \t:";
cin>>balance;
cout<<"Congratulations! "<<first_name + " " + middle_name + " " +last_name<<" \n";
cout<<"Your account is created";
disp();
}
double SI(double principle, float rate, int day)
{
return (principle*rate*(day/365))/100;
}
void account::inc_balance(double a)
{
cout<<"Enter today's date in form of 'DD MM YY'\t:";
cin>>dep_date.day>>dep_date.month>>dep_date.year;
balance += SI(balance, 5.00, diff_date(max_date, dep_date));
max_date.day = dep_date.day; max_date.month = dep_date.month; max_date.year = dep_date.year;
balance +=a;
cout<<"Congrats! Your amount successfully deposited"<<'\n';
cout<<"Now your current balance is Rs."<<balance<<'\n';
system("pause");
}
void account::tran_balance(double a)
{
cout<<"Enter today's date in form of 'DD MM YY'\t:";
cin>>with_date.day>>with_date.month>>with_date.year;
balance += SI(balance, 5.00, diff_date(max_date, with_date));
max_date.day = with_date.day; max_date.month = with_date.month; max_date.year = with_date.year;
balance +=a;
}
void account::dec_balance(double a)
{
if(balance-a>=0)
{
cout<<"Enter today's date in form of 'DD MM YY'\t:";
cin>>with_date.day>>with_date.month>>with_date.year;
cout<<with_date.day<<" "<<with_date.month<<" "<<with_date.year<<'\n';
cout<<max_date.day<<" "<<max_date.month<<" "<<max_date.year<<'\n';
cout<<diff_date(max_date, with_date)<<'\n';
cout<<SI(balance, 5.00, diff_date(max_date, with_date));
balance += SI(balance, 5.00, diff_date(max_date, with_date));
max_date.day = with_date.day; max_date.month = with_date.month; max_date.year = with_date.year;
balance -=a;
cout<<"Amount withdrawn successfully"<<'\n';
cout<<"Your current balance is Rs."<<balance<<'\n';
system("pause");
}
else cout<<"Sorry, amount can't be withdraw:"<<'\n';
}
void account::disp()
{
cout<<"First Name \t:"<<first_name<<'\n';
cout<<"Middle Name \t:"<<middle_name<<'\n';
cout<<"Last Name \t:"<<last_name<<'\n';
cout<<"Permanent Address \t:"<<address<<'\n';
cout<<"Mobile number \t:"<<mobile_no<<'\n';
cout<<"Balance :\t"<<balance<<'\n';
cout<<"Type of account"<<type<<'\n';
cout<<"A/c no.: \t"<<account_no<<'\n';
system("pause");
}
main()
{
string pass = "";
char ch;
cout<<"Please enter the password to enter the system"<<'\n';
ch = _getch();
while(ch != 13)
{//character 13 is enter
pass.push_back(ch);
cout << '*';
ch = _getch();
}
if(pass == "S1991")
{
cout << "\nAccess granted :\n";
cout<<"Welcome"<<'\n'<<'\n';
system("pause");
system("CLS");
int c1,c2;
int c = 0;
account member[10];
while(c1 != 5)
{
cout<<"Press 1: To create a new account:"<<'\n'<<"Press 2: To access the existing a/c:"<<'\n';
cin>>c1;
switch(c1)
{
case 1:
{
member[c++].get_detail();
system("CLS");
break;
}
case 2:
{
int a;
cout<<"Enter your a/c no."<<'\n';
cin>>a;
if(a-100000 >= 0 && a-100000 <= c)
{
while(c2 != 5)
{
system("CLS");
cout<<"Press 1: To deposite:"<<'\n'<<"Press 2: To withdraw:"<<'\n'<<"Press 3: To transfer money"<<'\n'<<"Press 4: To display details"<<'\n'<<"Press 5: To exit to main menu"<<'\n';
cin>>c2;
switch(c2)
{
case 1:
{
double amount;
cout<<"Enter the amount to be deposite"<<'\n';
cin>>amount;
member[a-100000].inc_balance(amount);
break;
}
case 2:
{
double amount;
cout<<"Enter the amount to be withdraw"<<'\n';
cin>>amount;
member[a-100000].dec_balance(amount);
break;
}
case 3:
{
double amount;
int b;
cout<<"Enter the amount to be transfer"<<'\n';
cin>>amount;
cout<<"Enter the a/c no to which amount is to be transfer"<<'\n';
cin>>b;
member[a-100000].dec_balance(amount);
member[b-100000].tran_balance(amount);
break;
}
case 4:
{
member[a-100000].disp();
break;
}
case 5:
{
break;
}
}
}
}
else {cout<<"A/C no. invalid"<<'\n'; break;}
}
case 5:
{
break;
}
}



}
}
system("pause");
}
Last edited on
Please first put it in code form. That's easier to read, and this is quite a lot of text :)
As Fransje said, code tags will help others diagnose your issue much easier.

One problem I see is that you never initialize c2.

int c1,c2;

and then the next reference to c2 is in the while loop:

while (c2 != 5)

try:

int c1, c2 = 0;

In this programm, after entering to c2 and exiting and againg entering to c2 makes some problem, why??

If that doesn't fix it you should definately fix your code so we can more easily read it. Also, what's the problem that you encounter when running the program past c2 twice?
I have edited!
problem is with only main()
and problem is not for initialitiong c1, c2.
its some time else.......
i'm able to rotate the loop, i don't know why??
pls help me.....
closed account (o3hC5Di1)
Hi there,

I don't think you understood what was meant.
If you put your code in code blocks like so: [code ]//code here[/code]

It looks like this:

1
2
3
4
5
6
#include <iostream>
int main()
{
    string text "look at this pretty code!";
    std::cout << text;
}


Also, indentation will make it more readable: http://en.wikipedia.org/wiki/Programming_style#Indentation

All the best,
NwN
Last edited on
solved the problem......
in while(c2!=5) it automatically taking c2=5 so my loop was no starting...
now i got it..
thanks
while(c2!=5) does not assign any value in c2.

You are confusing it with
while(c2=5).

So your problem is elsewhere
Topic archived. No new replies allowed.