Sign in with
Sign up | Sign in
Your question

Any help on this source code that i had compiled? It shows wrong output.

Tags:
  • Windows 7
  • Borland
  • c++
Last response: in Opinions and Experiences
Share
March 19, 2014 7:53:53 PM

  1. #include <iostream.h>
  2. #include <conio.h>
  3. #include <stdlib.h>
  4.  
  5. float CalcPriceMember1(int,float&,int&);
  6. float CalcPriceMember2(int,float&,int&);
  7. float CalcPriceNonMember1(int,float&,int&);
  8. float CalcPriceNonMember2(int,float&,int&);
  9. void EnterName();
  10. void MemberType();
  11. void PCType();
  12. float TotalSales(float, float, float, float);
  13.  
  14. main()
  15. {
  16. //VARIABLE DECLARATION
  17. char response;
  18. int hours;
  19. int count;
  20. float member_price,member_price2,non_member_price,non_member_price2;
  21. float jumlahbayar, jumlahjualan;
  22. char ahli [4];
  23. char nama [15];
  24. char jenispc [10];
  25.  
  26. //INPUT FROM USER
  27. cout<<"-------------------------------------------------------------"<<endl;
  28. cout<<" |Welcome to MYCyber Cafe| "<<endl;
  29. cout<<" "<<endl;
  30. cout<<"_______________________________¶¶¶¶¶¶¶¶¶_____________________"<<endl;
  31. cout<<"_____________________________¶¶__________¶¶__________________"<<endl;
  32. cout<<"_______________¶¶¶¶¶______¶¶_______________¶¶________________"<<endl;
  33. cout<<"______________¶_____¶____¶¶_____¶¶____¶¶_____¶¶______________"<<endl;
  34. cout<<"______________¶_____¶___¶¶______¶¶____¶¶_______¶¶____________"<<endl;
  35. cout<<"______________¶____¶__¶¶________¶¶____¶¶________¶¶___________"<<endl;
  36. cout<<"_______________¶___¶___¶_________________________¶¶__________"<<endl;
  37. cout<<"_____________¶¶¶¶¶¶¶¶¶¶¶¶________________________¶¶__________"<<endl;
  38. cout<<"____________¶____________¶_¶¶_____________¶¶_____¶¶__________"<<endl;
  39. cout<<"___________¶¶____________¶__¶¶____________¶¶_____¶¶__________"<<endl;
  40. cout<<"__________¶¶´´´¶¶¶¶¶¶¶¶¶¶¶____¶¶________¶¶_______¶¶__________"<<endl;
  41. cout<<"__________¶_______________¶_____¶¶¶¶¶¶¶_________¶¶___________"<<endl;
  42. cout<<"__________¶¶______________¶____________________¶¶____________"<<endl;
  43. cout<<"___________¶___¶¶¶¶¶¶¶¶¶¶¶¶___________________¶¶_____________"<<endl;
  44. cout<<"___________¶¶___________¶__¶¶________________¶¶______________"<<endl;
  45. cout<<"____________¶¶¶¶¶¶¶¶¶¶¶¶_____¶¶____________¶¶________________"<<endl;
  46. cout<<"________________________________¶¶¶¶¶¶¶¶¶¶¶__________________"<<endl;
  47. cout<<" "<<endl;
  48. cout<<" AWESOME!!! "<<endl;
  49. cout<<"-------------------------------------------------------------"<<endl;
  50. cout<<"Do you want to continue? YES='Y' or NO='N' :";
  51. cin>>response;
  52. //REPETITION
  53. while (response!='N')
  54. {
  55. cout<<"Price will be calculated based on the hour input by the user."<<endl;
  56. cout<<" <MEMBER> <NON MEMBER> "<<endl;
  57. cout<<"<PREMIUM>=RM6 PER HOUR WITH 30% DISCOUNT RM6 PER HOUR "<<endl;
  58. cout<<"<REGULAR>=RM4 PER HOUR WITH 30% DISCOUNT RM4 PER HOUR "<<endl;
  59. cout<<"-------------------------------------------------------------"<<endl;
  60. EnterName();
  61. MemberType();
  62. PCType();
  63. cout<<"Enter the required hours :";
  64. cin>>hours;
  65.  
  66. //COMPARISON
  67. if (strcmp(ahli,"YES")==0)
  68. {
  69. if (strcmp(jenispc,"PREMIUM")==0)
  70. {
  71. //OPERATION
  72. CalcPriceMember1 (hours,member_price,count);
  73. }
  74. else if (strcmp(jenispc,"REGULAR")==0)
  75. {
  76. //OPERATION
  77. CalcPriceMember2(hours,member_price2,count);
  78. }
  79. }
  80. else if (strcmp(ahli,"NOT")==0)
  81. {
  82. if (strcmp(jenispc,"PREMIUM")==0)
  83. {
  84. //OPERATION
  85. CalcPriceNonMember1 (hours,non_member_price,count);
  86. }
  87. else if (strcmp(jenispc,"REGULAR")==0)
  88. {
  89. //OPERATION
  90. CalcPriceNonMember2 (hours,non_member_price2,count);
  91. }
  92. }
  93.  
  94.  
  95. //DISPLAY THE RECEIPT
  96. jumlahbayar=member_price,member_price2,non_member_price,non_member_price2;
  97. cout<<" "<<endl;
  98. cout<<"======================================================="<<endl;
  99. cout<<" MYCyber Cafe Billing Receipt "<<endl;
  100. cout<<"======================================================="<<endl;
  101. cout<<"User :"<<(strcpy, nama)<<endl;
  102. cout<<"Member type :"<<(strcpy,ahli)<<endl;
  103. cout<<"PC type :"<<(strcpy,jenispc)<<endl;
  104. cout<<"Hour(s) spent :"<<hours<<endl;
  105. cout<<"Total pay(RM) :"<<jumlahbayar<<endl;
  106. cout<<"==============THANK YOU PLEASE COME AGAIN=============="<<endl;
  107. cout<<" "<<endl;
  108. cout<<"Do you want to continue YES='Y' or NO='N' :";
  109. cin>>response;
  110. }
  111.  
  112.  
  113. //DISPLAY THE RESULT TOTAL SALES CALCULATED PER DAY
  114. jumlahjualan=TotalSales(member_price,member_price2,non_member_price,non_member_price2);
  115. cout<<" "<<endl;
  116. cout<<" "<<endl;
  117. cout<<"======================================================="<<endl;
  118. cout<<" MYCyber Cafe Total Sales Collected "<<endl;
  119. cout<<"======================================================="<<endl;
  120. cout<<"Total Sales Collected Per Day (RM) : "<<jumlahjualan<<endl;
  121. cout<<"Number Of Customers Per Day : "<<count<<endl;
  122.  
  123. getch();
  124. }
  125.  
  126. //FUNCTION DEFINITION
  127. void EnterName()
  128. {
  129. char name[15];
  130. cout<<"Please enter your first name :";
  131. cin>>name;
  132. }
  133.  
  134. void MemberType()
  135. {
  136. char member[4];
  137. cout<<"Are you a member? (YES) or (NOT) :";
  138. cin>>member;
  139. }
  140.  
  141. void PCType()
  142. {
  143. char pctype[8];
  144. cout<<"Which type of PC are you prefer (PREMIUM) or (REGULAR) :";
  145. cin>>pctype;
  146. }
  147.  
  148. float TotalSales(float total1,float total2, float total3, float total4)
  149. {
  150. float total;
  151. total=total1+total2+total3+total4;
  152. return total;
  153. }
  154.  
  155.  
  156. float CalcPriceMember1 (int jam,float& member_price,int& count)
  157. {
  158. member_price=(jam*6.00)-(0.3*jam*6.00);
  159. count=count+1;
  160. return member_price, count;
  161. }
  162.  
  163. float CalcPriceMember2 (int jam,float& member_price2,int& count)
  164. {
  165. member_price2=(jam*4.00)-(0.3*jam*4.00);
  166. count=count+1;
  167. return member_price2, count;
  168. }
  169.  
  170. float CalcPriceNonMember1 (int jam,float& non_member_price,int& count)
  171. {
  172. non_member_price=jam*6.00;
  173. count=count+1;
  174. return non_member_price, count;
  175. }
  176.  
  177. float CalcPriceNonMember2 (int jam,float& non_member_price2,int& count)
  178. {
  179. non_member_price2=jam*4.00;
  180. count=count+1;
  181. return non_member_price2, count;
  182. }

More about : source code compiled shows wrong output

a b $ Windows 7
March 19, 2014 8:06:27 PM

Firstly, look into constants. They're useful.

Secondly, what's going wrong with it?
m
0
l
March 19, 2014 8:13:53 PM

Someone Somewhere said:
Firstly, look into constants. They're useful.

Secondly, what's going wrong with it?


I had look through it.
It suppose to print the receipt but the output is wrong there.
Did you know it?
m
0
l
a b $ Windows 7
March 19, 2014 8:31:41 PM

Define 'wrong'. I don't know what it's supposed to write. I don't know if it's the values or formatting that's wrong.
m
0
l
March 19, 2014 9:12:03 PM

Someone Somewhere said:
Define 'wrong'. I don't know what it's supposed to write. I don't know if it's the values or formatting that's wrong.


For example if you enter your name, member type, pctype and hours, it should display the same things as your input. But something unknown characters came out at the User, member type, pc type hours and total pay section at the receipt.
hope u understand it.
m
0
l
!