• 0

swich, no output


Question

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?

post-505691-0-00288900-1380473727.png

Link to comment
Share on other sites

Recommended Posts

  • 0

Well now you don't have a loop anymore, so the program only ever asks one question: is this what you want? Looks like you were confusing loops and switch statements and never really intended to use a loop in the first place. Anyway, glad you figured it out. :)

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.