String literals in C++ have types of constant charater arrrays.
But in any case the function definition
void interestCal(char *x,int y,int z){
accountType=&x;
depositAmt=y;
period=z;
if(accountType=="A"){
interestAmt=depositAmt*0.5*period;
}else if(accountType=="B"){
interestAmt=depositAmt*0.05*period;
}else if(accountType=="C"){
interestAmt=depositAmt*0.05*period;
}
}
is wrong.
As the compiler warns the first parameter should have type const char *
if you pass string literals as arguments to the function.
This statement
accountType=&x;
is invalid. Thje right operand &x
has type char **
while the left operand has type
char *
because accountType is declared as
char *accountType;
This
if(accountType=="A"){
and other if else statements are also invalid. Here you are tryying to compare pointers.
It would be much simpler and more correctly if you defined accountType as
char accountType;
and the function would look as
void interestCal( char x, int y, int z )
{
accountType = x;
depositAmt = y;
period = z;
if ( accountType == 'A' )
{
interestAmt = depositAmt * 0.5 * period;
}
else if ( accountType == 'B' )
{
interestAmt = depositAmt * 0.05 * period;
}
else if( accountType == 'C' )
{
interestAmt = depositAmt * 0.05 * period;
}
}
and it would be called from main as
b1.interestCal( 'A', 1000, 12 );
b1.interestCal( 'B', 1000, 12 );
b1.interestCal( 'C', 1000, 12 );
Also if indeed the three if-else statements have the same compound statement then they could be rewritten as one if statement
if ( accountType == 'A' || accountType == 'B' || accountType == 'C')
{
interestAmt = depositAmt * 0.05 * period;
}