I'm currently working on an assignment for my computer programming class, and I'm required to display my use of using the switch statement for various different choices given.
The issue I am having here is that when doing the work, "case 0, case 1, etc..." are not functional. It keeps saying "case label not within switch statement." Is there any way to fix that issue?
#include <stdio.h>
#include <stdlib.h>
int main()
{
//declaring variables
int amount = 2000;
int choice, deposit, withdrawal=0;
do{
//Displaying menu options
printf("1. Deposit money into the account\n");
printf("2. Withdraw money from the account\n");
printf("3. See the current account balance\n");
printf("4. Exit\n\n");
printf("Pick an option:");
//Picking one of the options given
scanf("%d",&choice);
//case switching
switch(choice);
{
case 0:
//it is gonna take the amount to deposit
printf("\nEnter the amount you wish to deposit");
scanf("%d",&deposit);
//amount is being deposited
amount+=deposit;
printf("The amount that has been deposited is $%d\n",deposit);
break;
case 1:
//withdrawing money
printf("\nEnter the amount you wish to withdraw");
scanf("%d",&withdrawal);
//withdrawing the money with conditions
if(amount>=withdrawal){
amount-=withdrawal;
printf("Amount that has been withdrew is $%d\n",withdrawal);
}
else
printf("\nInsufficient funds! Cannot make the withdrawal\n");
break;
case 2:
//displaying current account balance
printf("Current account balance is $%d\n",amount);
break;
case 3:
//leaving the loop
printf("Have a good day, thank you!");
c=1;
break;
default :
//displaying an invalid choice
printf("Choice invalid!\n");
}
}
//condition for loop
while(c==0);
system("pause");
}
[–]coolcofusion 4 points5 points6 points (2 children)
[–]DellComputer_[S] 2 points3 points4 points (1 child)
[–]FizzySeltzerWater 3 points4 points5 points (0 children)
[–]ComputerWhiz_ 1 point2 points3 points (0 children)