| | |
Clear getchar in a loop
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2003
Posts: 6
Reputation:
Solved Threads: 0
It's the getchar() for the computer value.
Thanks...
___________
Thanks...
___________
C Syntax (Toggle Plain Text)
#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); }
Last edited by Crowe182; Oct 7th, 2003 at 10:36 pm.
![]() |
Similar Threads
- ADVANTAGES of using while and do-while loop in C++ (C++)
- for loop compile error (C++)
- string .clear() (C++)
- Bubble sort & File output jibrish errors??? (C)
- need help asap :) (Java)
Other Threads in the C Forum
- Previous Thread: C Help!!!
- Next Thread: Need help with DirectX code
| Thread Tools | Search this Thread |
Tag cloud for C
adobe ansi api array arrays bash binarysearch centimeter char convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic fflush file fork frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hardware highest homework i/o ide inches infiniteloop initialization interest kilometer km lazy linked linkedlist linux linuxsegmentationfault list locate logical_drives match matrix meter microsoft motherboard multi mysql open opendocumentformat opensource openwebfoundation owf pattern pdf performance pointer pointers posix power problem probleminc program programming pyramidusingturboccodes read recursion recv repetition scanf scheduling segmentationfault send shape single socketprograming socketprogramming spoonfeeding stack standard strchr string strings structures suggestions system systemcall test testautomation unix user voidmain() wab win32api windows.h





