C Help!!!

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2003
Posts: 6
Reputation: Crowe182 is an unknown quantity at this point 
Solved Threads: 0
Crowe182 Crowe182 is offline Offline
Newbie Poster

C Help!!!

 
0
  #1
Oct 7th, 2003
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

_________
  1. #include <iostream.h>
  2. #include <stdio.h>
  3.  
  4. void main()
  5. {
  6. char mon,
  7. prin,
  8. computer;
  9.  
  10.  
  11. int customer = 0,
  12. pentium = 0,
  13. pentium2 = 0,
  14. response;
  15.  
  16. double s = 0, //pentium
  17. p = 0, //pentium II
  18. printer = 0,
  19. monitor = 0,
  20. sub_total = 0,
  21. total = 0,
  22. days = 0;
  23.  
  24. do
  25. {
  26.  
  27. printf("\nDo you want to rent a Pentium or a Pentium II system? ");
  28. printf("\nEnter 'S' for a Pentium or 'P' for a Pentium II: ");
  29. getchar();
  30. computer = getchar();
  31.  
  32. printf("\nEnter the number of days you want to rent computer: ");
  33. scanf("%lf", &days);
  34.  
  35. if ((computer == 'S') || (computer == 's')) //Pentium
  36. {
  37. printf("\nDo you want to rent a printer (y/n): ");
  38. getchar();
  39. prin = getchar();
  40.  
  41. if ((prin == 'Y') || (prin == 'y')) //Printer
  42. {
  43. printf("\nDo you want to rent a monitor (y/n): ");
  44. getchar();
  45. mon = getchar();
  46.  
  47. if ((mon == 'Y') || (mon == 'y')) //Monitor
  48. {
  49. monitor += 15.00;
  50. sub_total = monitor * days;
  51. }
  52. else //No Monitor
  53. {
  54. printer += 13.50;
  55. sub_total = printer * days;
  56. }
  57. }
  58. else //No Printer
  59. {
  60. printf("\nDo you want to rent a monitor (y/n): ");
  61. getchar();
  62. mon = getchar();
  63.  
  64. if ((mon == 'Y') || (mon == 'y')) //Monitor or Not
  65. {
  66. monitor = 12.50;
  67. sub_total = monitor * days;
  68. }
  69. else //No Monitor
  70. {
  71. p += 10.50;
  72. sub_total = p * days;
  73. }
  74. }
  75. printf("\nYour subtotal is $ %7.2f", sub_total);
  76. ++pentium;
  77. }
  78. else // Pentium II
  79. {
  80. printf("\nDo you want to rent a printer (y/n): ");
  81. getchar();
  82. prin = getchar();
  83.  
  84. if ((prin == 'Y') || (prin == 'y')) //Printer
  85. {
  86. printf("\nDo you want to rent a monitor (y/n): ");
  87. getchar();
  88. mon = getchar();
  89.  
  90. if ((mon == 'Y') || (mon == 'y')) //Monitor
  91. {
  92. monitor += 21.00;
  93. sub_total = monitor * days;
  94. }
  95. else //No Monitor
  96. {
  97. printer += 19.00;
  98. sub_total = printer * days;
  99. }
  100. }
  101. else //No Printer
  102. {
  103. printf("\nDo you want to rent a monitor (y/n): ");
  104. getchar();
  105. mon = getchar();
  106.  
  107. if ((mon == 'Y') || (mon == 'y')) //Monitor or Not
  108. {
  109. monitor = 18.50;
  110. sub_total = monitor * days;
  111. }
  112. else //No Monitor
  113. {
  114. p += 15.50;
  115. sub_total = p * days;
  116. }
  117. }
  118. printf("\nYour subtotal is $ %7.2f", sub_total);
  119. ++pentium2;
  120. }
  121. printf("\nDo you want to rent another computer?(y/n) ");
  122. getchar();
  123. response = getchar();
  124. total += sub_total;
  125. ++customer;
  126. }
  127. while ((response == 'Y') || (response == 'y'));
  128. printf("\nThe total number of customers are: %d", customer);
  129. printf("\nThe total number of Pentium's rented are: %d", pentium);
  130. printf("\nThe total number of Pentium II's rented are: %9d", pentium2);
  131. printf("\nThe total rental charges for all the computers: %17.2f\n", total);
  132. }
Last edited by Crowe182; Oct 7th, 2003 at 2:14 pm.
Reply With Quote Quick reply to this message  
Join Date: Feb 2003
Posts: 282
Reputation: Roberdin will become famous soon enough Roberdin will become famous soon enough 
Solved Threads: 6
Team Colleague
Roberdin Roberdin is offline Offline
Supreme Evil Overlord

Re: C Help!!!

 
0
  #2
Oct 7th, 2003
Ergh, It's very difficult to read your code like that. Isn't there a code option or something?

Found it.

When typing code, wrap it in [CODE] and [/CODE] tags; and then indent stuff using the [INDENT] and [/INDENT]; for example:

  1. // This is some code:
  2.  
  3. if( something == true || somethingelse != false )
  4. {<blockquote>
  5. // This has been indented using the Indent tags.
  6. printf('blah blah blah');
  7. </blockquote>}
Reply With Quote Quick reply to this message  
Join Date: Oct 2003
Posts: 6
Reputation: Crowe182 is an unknown quantity at this point 
Solved Threads: 0
Crowe182 Crowe182 is offline Offline
Newbie Poster

Re: C Help!!!

 
0
  #3
Oct 7th, 2003
OK got the changes made. How is that??
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 12,048
Reputation: cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light 
Solved Threads: 129
Administrator
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: C Help!!!

 
0
  #4
Oct 7th, 2003
Remember, you can also go to the user control panel, and somewhere in your preference options, you can set to use a WYSIWYG editor to edit posts. Unfortunately, I have to run off to class in a few minutes, so don't really have time to look at this program right now.
Dani the Computer Science Gal
Follow my Twitter feed! twitter.com/DaniWeb
And if you're interested in Internet marketing there is twitter.com/DaniWebAds
Reply With Quote Quick reply to this message  
Join Date: Oct 2003
Posts: 6
Reputation: Crowe182 is an unknown quantity at this point 
Solved Threads: 0
Crowe182 Crowe182 is offline Offline
Newbie Poster

Re: C Help!!!

 
0
  #5
Oct 7th, 2003
no problem, just let me know when you get a chance.

Thanks....
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC