begginner and I need help, switch statement
this is my first post and I have looked around on the board and havn't really found anything to help me
I understand the very basics of c and I have this program but when it goes into the switch statement under case 1 it jumps past a line to take the user input and I can't figure it out
Code:
menu(); - - - /* calls menu function, displays menu */
scanf("%d", &opt); - - - /* scans for input choice */
while (opt != 3) - - -
{ switch(opt) - /* sets up the switch for options */
{ case 1: - /* option 1 if customer deposits */
printf("Now Please Enter Your User ID: ");
gets(cid); <----------
i = search(cid);
if(i == -1)
puts("\nWe don't show that ID, please try again\n");
puts("\nPlease enter amount you want to deposit\n");
scanf("%f",&amount);
c[i].balance = c[i].balance + amount;
printf("\n Your new account balance is %f", c[i].balance);
break;
case 2:
.
.
.
int search(char cid[])
{ int i;
for(i = 0; i < 5; i++)
if(strcmp(c[i].id, cid) == 0)
return i;}
I have a function search but it jumps past the gets line and goes right to please enter amount to deposit. I need it to be able to retrieve a certain user ID and it jumps over that gets statement
Please help
that worked but another problem
thanks, I went with the first approach, but now I have a new error
Code:
while (opt != 3) /* while option is not 3 it goes to a switch */
switch (opt) /* sets up the switch for options */
case 1: /* option 1 if customer deposits */
puts("Now Please Enter Your User ID: ");
gets(cid);
i = search(cid);
puts("\nPlease enter amount you want to deposit\n");
scanf("%f",&amount);
c[i].balance = c[i].balance + amount;
printf("\n Your new account balance is %.2f\n", c[i].balance);
break;
case 2:
puts("blah");
break;
the compiler now says that the break in case 1 is not part of a case and that case 2 isn't in the switch statement
what is terminating the switch ?
thanks again