I am writing this program for my computer class. I am having a problem with my do/while loop. I can go through my main IF statement, but when I go through the loop a second time, I enter 'S' os 's' for computer type it skips past the main IF statement. Do i need to clear my computer variable before going through the loop again, if so how do I do that. Please help.
Thanks,
Crowe182
_________
#include <iostream.h>
#include <stdio.h>
void main()
{
char mon,
prin,
computer;
int customer = 0,
pentium = 0,
pentium2 = 0,
response;
double s = 0, //pentium
p = 0, //pentium II
printer = 0,
monitor = 0,
sub_total = 0,
total = 0,
days = 0;
do
{
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: ");
getchar();
computer = 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;
sub_total = monitor * days;
}
else //No Monitor
{
printer += 13.50;
sub_total = printer * days;
}
}
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;
sub_total = monitor * days;
}
else //No Monitor
{
p += 10.50;
sub_total = p * days;
}
}
printf("\nYour subtotal is $ %7.2f", sub_total);
++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;
sub_total = monitor * days;
}
else //No Monitor
{
printer += 19.00;
sub_total = printer * days;
}
}
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;
sub_total = monitor * days;
}
else //No Monitor
{
p += 15.50;
sub_total = p * days;
}
}
printf("\nYour subtotal is $ %7.2f", sub_total);
++pentium2;
}
printf("\nDo you want to rent another computer?(y/n) ");
getchar();
response = getchar();
total += sub_total;
++customer;
}
while ((response == 'Y') || (response == 'y'));
printf("\nThe total number of customers are: %d", customer);
printf("\nThe total number of Pentium's rented are: %d", pentium);
printf("\nThe total number of Pentium II's rented are: %9d", pentium2);
printf("\nThe total rental charges for all the computers: %17.2f\n", total);
}