I am getting an illegal case error when compiling the following code listed below. I am a novice, I have reread the section on switch statements in the 4 books I have, and cannot figure out what I am doing wrong. Please steer me in the right direction.
Code:
/* This program is the ATM machine */
#include <stdio.h>
/* Declare Global Variables */
/* Line 20 */
float checking_balance = 5325.72;
float savings_balance = 20456.98;
int menu_choice;
/* Print the ATM machine menu for the customer */
void print_menu(void)
{
printf("USA Bank \n");
/* Line 30 */
printf("1 - Withdrawls \n");
printf("2 - Deposits \n");
printf("3 - Transfers \n");
printf("4 - Balances \n");
printf("5 - Quit \n");
}
/* Line 40 */
void get_menu_choice(void)
{
printf("Enter you selection:");
scanf("%i", &menu_choice);
}
/* defining functions */
/* Line 50 */
int checking_or_savings(void) /* Needed to add two underscores for this to work */
{
int n;
printf("Enter 1 for checking or a 0 for savings \n");
scanf("%i", &n);
return (n);
}
/* Line 60 */
void balances(void)
{
printf("checking: %.2f\n", checking_balance);
printf("savings: %.2f\n", savings_balance);
}
/* Line 70 */
/* need to add some error checking to this function */
void withdrawls(void)
{
int type;
float w;
printf("Which account type? \n");
type = checking_or_savings();
/* Line 80 */
printf("Withdrawl amount:");
scanf("%f", &w);
if(type)
checking_balance = checking_balance - w;
else
savings_balance = savings_balance - w;
}
/* Line 90 */
void deposits(void)
{
int type;
float d;
printf("Which account type? \n");
type = checking_or_savings();
/* Line 100 */
printf("Deposit amount:");
scanf("%f", &d);
if(type)
checking_balance = checking_balance + d;
else
savings_balance = savings_balance + d;
}
/* Line 110 */
/* need to add some error checking to this function */
void transfers(void)
{
int type;
float amount;
printf("Source account:");
type = checking_or_savings();
/* Line 120 */
printf("Enter amount of transfer:");
scanf("%f", &amount);
if(type == 1)
{
checking_balance = checking_balance - amount;
savings_balance = savings_balance + amount;
}
else
/* Line 130 */
{
savings_balance = savings_balance - amount;
checking_balance = checking_balance + amount;
}
}
void main(void)
/* Line 140 */
{
do
{
print_menu();
get_menu_choice();
switch(menu_choice);
{
case '1': withdrawls();
break;
case 2: deposits();
break;
case 3: transfers();
break;
case 4: balances();
break;
case 5: printf("Thank You for your business");
break;
default : printf("Invalid selection... Please try again \n");
break;
}
}
while(menu_choice != 5);
}
I get the following errors from Microsoft Visual C++ 6.0 when I compile
Compiling...
Week 2 Problem ATM.c
C:\Program Files\Microsoft Visual Studio\MyProjects\Week 2 Problem ATM\Week 2 Problem ATM.c(21) : warning C4305: 'initializing' : truncation from 'const double ' to 'float '
C:\Program Files\Microsoft Visual Studio\MyProjects\Week 2 Problem ATM\Week 2 Problem ATM.c(22) : warning C4305: 'initializing' : truncation from 'const double ' to 'float '
C:\Program Files\Microsoft Visual Studio\MyProjects\Week 2 Problem ATM\Week 2 Problem ATM.c(152) : error C2046: illegal case
C:\Program Files\Microsoft Visual Studio\MyProjects\Week 2 Problem ATM\Week 2 Problem ATM.c(154) : error C2046: illegal case
C:\Program Files\Microsoft Visual Studio\MyProjects\Week 2 Problem ATM\Week 2 Problem ATM.c(156) : error C2046: illegal case
C:\Program Files\Microsoft Visual Studio\MyProjects\Week 2 Problem ATM\Week 2 Problem ATM.c(158) : error C2046: illegal case
C:\Program Files\Microsoft Visual Studio\MyProjects\Week 2 Problem ATM\Week 2 Problem ATM.c(160) : error C2046: illegal case
C:\Program Files\Microsoft Visual Studio\MyProjects\Week 2 Problem ATM\Week 2 Problem ATM.c(162) : error C2047: illegal default
Error executing cl.exe.
Week 2 Problem ATM.exe - 6 error(s), 2 warning(s)