# Thread: i need alil help with my switch question

1. never expect anyone to write a program for you in this forum, but since i see you've at least been trying i'll help you out.

Code:
```#include <stdio.h>

int main()
{
int swt=0, num1=0, num2=0, num3=0, num4=0, num5=0;
float awn1=0, awn2=0, awn3=0, awn4=0, awn5=0, total;

for(;;)  //infinite for statemtn basically a loop which never ends
{
printf ("\nEnter the product number(-1 to end): ");
scanf ("%d", &swt );
if(swt==-1)
break;

switch ( swt )
{
case 1:
printf ("Enter the amount for No.1: ");
scanf ("%d",&num1 );
awn1 = num1 * 2.98;
break;

case 2:
printf ("Enter the amount for No.2: ");
scanf ("%d", &num2 );
awn2 = num2 * 4.50;
break;

case 3:
printf ("Enter the amount for No.3: ");
scanf ("%d", &num3 );
awn3 = num3 * 9.98;
break;

case 4:
printf ("Enter the amount for No.4: ");
scanf ("%d", &num4 );
awn4 = num4 * 4.49;
break;

case 5:
printf ("Enter the amount for No.5: ");
scanf ("%d", &num5 );
awn5 = num5 * 6.87;
break;

default:
printf ("Incorrect number\n");
}
}

total = awn1+awn2+awn3+awn4+awn5;
printf ("\nThe total for you products is: %.2f",total); //total is float!
//%.2f prints the floating point total with 2 decimal places
getch();
return 0;
}```

2. A cut down version, showing the switch statement.

Code:
```#include <stdio.h>
#include <conio.h>

int main(void)
{
int  num1;
clrscr();

printf("Enter choice, 1 or 2: (x to exit) ");
while (scanf("%d", &num1) == 1)
{
switch (num1)
{
case 1:
printf("Doing stuff for 1\n");
break;
case 2:
printf("Doing stuff for 2\n");
break;
default:
printf("Doing stuff for default (ie Not 1 or 2)\n");
break;
}
printf("Enter choice, 1 or 2: (x to exit) ");
}

printf ("All done, press any key\n");
getch();
return(0);
}```

3. lol i beat you by a fraction of a sec