Problem Input and Output

Hi there

Firstly, i just copy the coding into this text, sorry for that, i'm just recently start, so i hope you guys can help me..

i have a problem that the accName didn't display when i run this program..

and the accLatest also become error when compile this file..



int main ()
{

int accNum ;
char accType[1] , accName[20] ;
float accBal , dividen , charge , accLatest ;

cout << "\nAccount Number ( Example : 12345 ) : " ;
cin >> accNum ;

cout << "\nAccount Type ( S = saving , C = checking : " ;
cin >> accType ;

cout << "\nCurrent Balance : " ;
cin >> accBal ;

if ( accType == "s" )
{
accName == "Savings_Accounts" ;

if ( accBal <= 1000.00 )

charge = 10.00 ;

else

charge = 0.00 ;

if ( accBal >= 1000.00 )

dividen = 0.04 ;

else

dividen = 0.00 ;
}
else
{
accName == "Checking_Accounts" ;

if ( accBal <= 5000.00 )

charge = 25.00 ;

else

charge = 0.00 ;

if ( accBal > 5000 )

dividen = 0.03 ;

else

dividen = 0.05 ;
}


accLatest = accBal - ( accBal * dividen ) ;

accLatest = accBal - charge ;

cout << "\nAccount Name : " << accNum ;
cout << "\nAccount Type : " << accType ;
cout << "\nAccount Name : " << accName ;
cout << "\nPrevious Month Balance RM : " << accBal ;
cout << "\n ( - ) Service Charge RM : " << charge ;
cout << "\n ( + ) Dividend RM : " << dividen ;
cout << "\nCurrent Balance RM : " << accLatest ;

return 0;
}
Last edited on
closed account (zb0S216C)
accName is an array of characters, not a string. You need to swap its type-specifier with char * (it should look like this: char *accName = "..."). Also, accName == "Savings_Accounts" is pointless. Actually, an even better solution would be to use string[1].

References:
[1]http://www.cplusplus.com/reference/string/string/


Wazzak
Last edited on
maybe try cin.ignore after cin... or use getline (cin, variable)

http://www.cplusplus.com/forum/articles/6046/
what the different between char and char*??
so, the better solution is to use string right? well, thanks for helping..

ow yeah, it said that accLatest is assinged to a value that is never used...
what is the problem and how to fix it??
You use

accName == "Savings_Accounts" ;

where == means equivalent.
To assign a value to a variable you need to use one equal sign.

accName = "Savings_Accounts" ;
Last edited on
Topic archived. No new replies allowed.