Hello everyone. I'm attempting to write a program that prompts the user for a quantity of partID's and then use a switch (loop) to id the part's unitprice for x amount of parts. then display the total for those parts. What I'm trying to do right now is just get the switch (loop) to work. I'm not exactly worried about the last part of the total right this second. What I have is :
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
void main()
{
int partID = 0;
double unitprice = 0;
int ch = 0;
printf("Please enter partID\n");
printf("Please enter q to quit\n");
ch = getch();
do{
switch(partID)
{
case 1:
unitprice = 1.30;
break;
case 2:
unitprice = 0.99;
break;
case 3:
unitprice = 2.50;
break;
case 4:
unitprice = 1.42;
break;
case 5:
unitprice = 1000000.00;
break;
default:
printf("Part cannot be found\n");
case 0:
partID++;
break;
}
}
while (partID != 0);
}
this is what it's outputting : (see picture below)
which is outputting nothing but the printf's . it wont even access the loop, nor will it exit. what am I don't wrong?
Question
Terabojin
Hello everyone. I'm attempting to write a program that prompts the user for a quantity of partID's and then use a switch (loop) to id the part's unitprice for x amount of parts. then display the total for those parts. What I'm trying to do right now is just get the switch (loop) to work. I'm not exactly worried about the last part of the total right this second. What I have is :
this is what it's outputting : (see picture below)
which is outputting nothing but the printf's . it wont even access the loop, nor will it exit. what am I don't wrong?
Link to comment
Share on other sites
26 answers to this question
Recommended Posts