944,153 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1378
  • C++ RSS
Nov 11th, 2005
0

what's wrong

Expand Post »
hi every1
i want to ask what wrong with my program
it all work allright just the zakat function when i run the program the output is garpege
here is the code
C++ Syntax (Toggle Plain Text)
  1. #include <iostream.h>
  2. #include <conio.h>
  3. #include <stdlib.h>
  4.  
  5. class Customer {
  6.  
  7. private:
  8. char name[20];
  9. char address[30];
  10. char city[20];
  11. char pcode[6];
  12. float acc_bal;
  13. double zak;
  14. public:
  15. Customer:: Customer() { // constructor
  16. acc_bal = 0.00;
  17. }
  18.  
  19. void getdata() {
  20. cout << "\nEnter your name: "; cin >> name;
  21. cout << "\nEnter your address: "; cin >> address;
  22. cout << "\nEnter your city: "; cin >> city;
  23. cout << "\nEnter your postal code: "; cin >> pcode;
  24. cout << "\nEnter current account balance: "; cin >> acc_bal;
  25. }
  26.  
  27. void deposit() {
  28. float dep;
  29. cout << "\nEnter amount to be deposited: ";
  30. cin >> dep;
  31. acc_bal += dep;
  32. }
  33.  
  34. void withdraw() {
  35. float wdraw;
  36. cout << "\nEnter amount to be withdrawn: "; cin >> wdraw;
  37. acc_bal -= wdraw;
  38. }
  39. void zakat()
  40. {
  41.  
  42. zak= (acc_bal*2.5)/100;
  43. }
  44.  
  45. void showdata() {
  46. cout << "Name: " << name;
  47. cout << "\nAddress: " << address;
  48. cout << "\nCity: " << city;
  49. cout << "\nPostal Code: " << pcode;
  50. cout << "\nAccount Balance: $" << acc_bal << endl;
  51. cout<<"Zakat is: "<<zak<<endl;
  52. }
  53.  
  54. };
  55.  
  56. int main() {
  57.  
  58. char choice;
  59. bool flag =0;
  60. int count = 0;
  61. int recnum;
  62. Customer cust[10];
  63.  
  64. while (flag == false) {
  65. cout << "\t\t\n\n" << "Main Menu";
  66. cout << "\t\n\n" << "Select by letter:";
  67. cout << "\t\n" << "a - Add a customer.";
  68. cout << "\t\n" << "d - Deposit money.";
  69. cout << "\t\n" << "w - Withdraw money.";
  70. cout << "\t\n" << "s - Show Account Information.";
  71. cout << "\t\n" << "q - Quit Application.\n\n";
  72. cout << "\t" << "Choice: ";
  73. cin>>choice ;
  74. switch(choice) {
  75. case 'a':
  76. system("cls");
  77. if (count > 10) {
  78. cout << "Can't add anymore records. Press any key to return to main menu.";
  79. getche();
  80. break;
  81. }
  82. count += 1;
  83. cust[count].getdata();
  84. system("cls");
  85. break;
  86.  
  87. case 'd':
  88. system("cls");
  89. cout << "\nEnter customer number: ";
  90. cin >> recnum;
  91. cust[recnum].deposit();
  92. system("cls");
  93. break;
  94.  
  95. case 'w':
  96. system("cls");
  97. cout << "\nEnter customer number: ";
  98. cin >> recnum;
  99. cust[recnum].withdraw();
  100. system("cls");
  101. break;
  102.  
  103. case 's':
  104. system("cls");
  105. cout << "\nEnter customer number: ";
  106. cin >> recnum;
  107. cust[recnum].showdata();
  108. getche();
  109. system("cls");
  110. break;
  111.  
  112. case 'q':
  113. flag = 1;
  114. break;
  115.  
  116. default:
  117. cout << "\nInvalid selection. Press a key to return to main menu.";
  118. getche();
  119. }
  120.  
  121. if (flag == true) {
  122. break;
  123. }
  124.  
  125. }
  126. return 0;
  127. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster
some one is offline Offline
129 posts
since Apr 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: CPU Task Scheduler
Next Thread in C++ Forum Timeline: Help! I'm new to pointers





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC