vendredi 31 juillet 2015

switch case loop statement

Hello i am having problem with my one assignment. I made one function name chequingsaving and when i call this function it prints some data which is correct but when i entered character depends on my selection of account it directly goes out of loop. if i entered correct character value then same thing happens.I am sending you that function code. help me to find out my mistake. the thing is i used also switch case but still it directly goes to default. same thing happens with if else loop.

void chequingsaving()  /*Chequing and saving account function*/
{
    char a;
    double r, Initialamount = 0;
    printf(" c) Chequing\n");
    printf(" s) Savings\n");
    printf("Which account would you like to use?\n");
    scanf("% c", &a);

    if (a == 'c' || a == 'C')
        {
            printf("Please enter the amount for deposit\n");
            scanf("% lf", &r);
            Initialamount = Initialamount + r;
            printf("Your chequing account balance is=%lf", Initialamount);
        }
    else
        if (a == 's' || a == 'S')
        {
            printf("Please enter the amount for deposit\n");
            scanf("%lf", &r);
            Initialamount = Initialamount + r;
            printf("Your chequing account balance is=%lf", Initialamount);
        }
        else

        printf("Invalid character\n");

} 

Aucun commentaire:

Enregistrer un commentaire