Is there a way to clear the getchar variable in a loop after you go through the loop the 1st time?

post code so I can help you:)

messed the code up, see next one. :o

It's the getchar() for the computer value.
Thanks...
___________

#include <iostream.h>
#include <stdio.h>

void main()
{
	char mon,
		 prin,
		 computer;


	int customer = 0,
		pentium = 0,
		pentium2 = 0,
		comp,
		response;

	double	s = 0, //pentium
			p = 0, //pentium II
			printer = 0,
			monitor = 0,
			rent = 0,
			sub_total = 0,
			total = 0,
			days = 0;

	do
	{

		s = 0,
		p = 0,
		printer = 0,
		monitor = 0,
		rent = 0,
		total = 0,
		days = 0;

		printf("\nDo you want to rent a Pentium or a Pentium II system? ");
		printf("\nEnter 'S' for a Pentium or 'P' for a Pentium II:	");
		computer = getchar();
		getchar();

		printf("\nEnter the number of days you want to rent computer:	");
		scanf("%lf",	&days);

		if ((computer == 'S') || (computer == 's')) //Pentium 
		{	
			printf("\nDo you want to rent a printer (y/n):	");
			getchar();
			prin = getchar();

			if ((prin == 'Y') || (prin == 'y')) //Printer
			{
				printf("\nDo you want to rent a monitor (y/n):	");
				getchar();
				mon = getchar();

				if ((mon == 'Y') || (mon == 'y')) //Monitor
				{
				monitor += 15.00;
				rent = monitor * days;
				printf("\nYour rental charge for this computer is $ %5.2f", rent);
				}
				else //No Monitor
				{
				printer += 13.50;
				rent = printer * days;
				printf("\nYour rental charge for this computer is $ %5.2f", rent);
				}
			}
			else //No Printer
			{
				printf("\nDo you want to rent a monitor (y/n):	");
				getchar();
				mon = getchar();

				if ((mon == 'Y') || (mon == 'y')) //Monitor or Not
				{
				monitor = 12.50;
				rent = monitor * days;
				printf("\nYour rental charge for this computer is $ %5.2f", rent);
				}
				else //No Monitor
				{
				p += 10.50;
				rent = p * days;
				printf("\nYour rental charge for this computer is $ %5.2f", rent);
				}
			}
		++pentium;
		}
		else // Pentium II
		{
			printf("\nDo you want to rent a printer (y/n):	");
			getchar();
			prin = getchar();

			if ((prin == 'Y') || (prin == 'y')) //Printer
			{
				printf("\nDo you want to rent a monitor (y/n):	");
				getchar();
				mon = getchar();

				if ((mon == 'Y') || (mon == 'y')) //Monitor
				{
				monitor += 21.00;
				rent = monitor * days;
				printf("\nYour rental charge for this computer is $ %5.2f", rent);
				}
				else //No Monitor
				{
				printer += 19.00;
				rent = printer * days;
				printf("\nYour rental charge for this computer is $ %5.2f", rent);
				}
			}
			else //No Printer
			{
				printf("\nDo you want to rent a monitor (y/n):	");
				getchar();
				mon = getchar();

				if ((mon == 'Y') || (mon == 'y')) //Monitor or Not
				{
				monitor = 18.50;
				rent = monitor * days;
				printf("\nYour rental charge for this computer is $ %5.2f", rent);
				}
				else //No Monitor
				{
				p += 15.50;
				rent = p * days;
				printf("\nYour rental charge for this computer is $ %5.2f", rent);
				}
			}
		++pentium2;
		}
	sub_total += rent;
	printf("\n-----------------------------------------------");
	printf("\nYour subtotal is:			$ %5.2f\n", sub_total);
	printf("\nDo you want to rent another computer?(y/n) ");
	getchar();
	response = getchar();
	total = sub_total;
	rent = 0;
	++customer;
	}
	while ((response == 'Y') || (response == 'y'));
	printf("\nThe total number of total computers rented:		%d", customer);
	printf("\nThe total number of Pentium's rented:			%d", pentium);
	printf("\nThe total number of Pentium II's rented:		%d", pentium2);
	printf("\nThe total rental charges for all the computers:	  $%6.2f\n", total);
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.