Conference Name Fee/Person Discount ASEE2012 RM800.00 10% for a group of 5 persons IEEE2012 RM750.00 15% for a group of 10 persons ENCON2012 RM700.00 5% for pair ICCNS2012 RM400.00 10% for a group of 10 persons The program output should look something like this: Select Conference: 1 – ASEE2012 2 – IEEE2012 3 – ENCON2012 4 – ICCNS2012 5 – Exit
continue : Your choice: 1 How many persons would like to register: 10 The conference fee would be RM6300.00 Note: Your program should only terminate when the ‘Exit’ choice being selected. (using selection method or switch method)
try using a loop (perhaps a do-while) containing a switch statement with cases corresponding to the possible user input, numbers from 1-5, and a default case which checks for bad input.
where i should put the calculation???after displaying the choice and the person??
you can have each calculation take place within each case, but after getting input from the user about the choice and the number of persons to be registered
oooh..okay..thanks..i'll try =D
#include<stdio.h> int main () { int choice, person; float fee; printf ("Select Conference\n"); printf ("1 -\t ASEE2012\n"); printf ("2 -\t IEEE2012\n"); printf ("3 -\t ENCON2012\n"); printf ("4 -\t ICCNS2012\n"); printf ("5 -\t Exit\n"); printf ("Your choice :"); scanf ("%d", &choice); while (choice <5) { printf ("\nHow many persons would like to register :"); scanf ("%d", &person); switch (choice) { case '1': if (person>=5) {fee = (800 * person )-(10/100*800*person); printf ("\nThe conference fee would be %.2f",fee);} else {fee = 800 * person; printf ("\nThe conference fee would be %.2f",fee);} break; case '2': if (person>=10) {fee = (750 * person )-(15/100*750*person); printf ("\nThe conference fee would be %.2f",fee);} else {fee = 750 * person; printf ("\nThe conference fee would be %.2f",fee);} break; case '3': if (person==2) {fee = (700 * person )-(5/100*700*person); printf ("\nThe conference fee would be %.2f",fee);} else {fee = 700 * person; printf ("\nThe conference fee would be %.2f",fee);} break; case '4': if (person>=10) {fee = (400 * person )-(10/100*400*person); printf ("\nThe conference fee would be %.2f",fee);} else {fee = 400 * person; printf ("%f",fee); printf ("\nThe conference fee would be %.2f",fee);} break; default: break; } } return 0; } i have make it..but i cant get it
Your while loop is around the calculation piece but not the input, so it never gets updated. Try using a do-while loop, do{ // menu code ///calculation code } while(choice < 5);
in the calculation code i should use switch right?? but when i put switch..the program didnt stop and keep asking the choice and person
you probably forgot to add break statements
break statement??when???
Did you change the code from the previous post? It is hard to see what is wrong without the updated code.
#include<stdio.h> int main () { int choice, person; float fee; do{ // menu code printf ("Select Conference\n"); printf ("1 -\t ASEE2012\n"); printf ("2 -\t IEEE2012\n"); printf ("3 -\t ENCON2012\n"); printf ("4 -\t ICCNS2012\n"); printf ("5 -\t Exit\n"); printf ("Your choice :"); scanf ("%d", &choice); printf ("\nHow many persons would like to register :"); scanf ("%d", &person); switch (choice) { case '1': if (person>=5) {fee = (800 * person )-(0.1*800.0*person); printf ("\nThe conference fee would be %f",fee);} else {fee = 800 * person; printf ("\nThe conference fee would be %f",fee);} break; case '2': if (person>=10) {fee = (750.00 * person )-(0.15*750.00*person); printf ("\nThe conference fee would be %f",fee);} else {fee = 750.00 * person; printf ("\nThe conference fee would be %f",fee);} break; case '3': if (person==2) {fee = (700.00 * person )-(0.05*700.00*person); printf ("\nThe conference fee would be %f",fee);} else {fee = 700 * person; printf ("\nThe conference fee would be %f",fee);} break; case '4': if (person>=10) {fee = (400.00 * person )-(0.10*400.00*person); printf ("\nThe conference fee would be %f",fee);} else {fee = 400.00 * person; printf ("%f",fee); printf ("\nThe conference fee would be %f",fee);} break; default: break; } ///calculation code } while(choice < 5); return 0; }
The issue is your case statements. You are checking an int versus a char. Change the lines from case '1': to case 1: removing the apostrophes.
still the same..it keep looping =(
I meant to say change all the case statements removing the apostrophe's and the other issue is the while(choice>5) make that while(choice>=5) or while(choice >4). The choice > 5 does is not false when you type in a 5.
finally!!okay..thanks a lot!!
Join our real-time social learning platform and learn together with your friends!