This one should be easy for you guys.
It's just some simple calculations that I want to display in a textbrowser, but the numbers come out insanely large or not at all what they should be.
I get no errors or anything like that.
I tried different ways of making the numbers into strings, although the results where different they where still wrong.

I made the ui in Designer.

oppg2.h:
Qt Code:
  1. #ifndef OPPG2_H
  2. #define OPPG2_H
  3.  
  4. #include "ui_oppg2.h"
  5.  
  6. class Oppg2 : public QWidget, private Ui::oppg2
  7. {
  8. Q_OBJECT
  9.  
  10. public:
  11. Oppg2(QWidget *parent=0);
  12.  
  13. public slots:
  14. void checkout();
  15. void clear();
  16. };
  17.  
  18. class PatientAccount : public QWidget, private Ui::oppg2
  19. {
  20.  
  21. public:
  22. void setDaysInHospital(int daysInHospital);
  23. void setDaysInHospitalCost(int daysInHospitalCost);
  24. void setTotalCharges(int totalCharges);
  25. int getDaysInHospitalCost();
  26. int getTotalCharges();
  27.  
  28. private:
  29. const static int dailyRate=40;
  30. int daysInHospital;
  31. int daysInHospitalCost;
  32. int totalCharges;
  33. };
  34.  
  35. class Surgery : public QWidget, private Ui::oppg2
  36. {
  37.  
  38. public:
  39. void setNumSurgery(int numSurgery);
  40. void setSurgeryCost(int surgeryCost);
  41. void setTotalSurgeryCost(int totalSurgeryCost);
  42. int getTotalSurgeryCost();
  43.  
  44. private:
  45. int numSurgery;
  46. int surgeryCost;
  47. int totalSurgeryCost;
  48. };
  49.  
  50. class Pharmacy : public QWidget, private Ui::oppg2
  51. {
  52.  
  53. public:
  54. void setNumMedication(int numMedication);
  55. void setPharmacyCost(int pharmacyCost);
  56. void setTotalPharmacyCost(int totalPharmacyCost);
  57. int getTotalPharmacyCost();
  58.  
  59. private:
  60. int numMedication;
  61. int pharmacyCost;
  62. int totalPharmacyCost;
  63. };
  64.  
  65. #endif
To copy to clipboard, switch view to plain text mode 

oppg2.cpp:
Qt Code:
  1. #include <QtGui>
  2. #include "oppg2.h"
  3.  
  4. //Start Oppg2 class
  5.  
  6. Oppg2::Oppg2(QWidget *parent)
  7. {
  8. setupUi(this);
  9.  
  10. connect(pushButton_checkout, SIGNAL(clicked()), this, SLOT(checkout()));
  11. connect(pushButton_clear, SIGNAL(clicked()), this, SLOT(clear()));
  12. }
  13.  
  14. void Oppg2::checkout()
  15. {
  16. PatientAccount PA;
  17. Surgery S;
  18. Pharmacy P;
  19.  
  20. int numDays;
  21. int numSurgery;
  22. int numMedication;
  23.  
  24. numDays=spinBox_days->value();
  25. numSurgery=spinBox_surgery->value();
  26. numMedication=spinBox_medication->value();
  27.  
  28. textBrowser->append("Number of days spent in hospital: " + QString::number(numDays));
  29. textBrowser->append("Cost of hospitalstay: " + QString::number(PA.getDaysInHospitalCost()));
  30. textBrowser->append("Type of surgery: " + comboBox_surgery->currentText());
  31. textBrowser->append("Number of " + comboBox_surgery->currentText() + " surgery: " + QString::number(numSurgery));
  32. textBrowser->append("Cost of surgery: " + QString::number(S.getTotalSurgeryCost()));
  33. textBrowser->append("Type of medication: " + comboBox_medication->currentText());
  34. textBrowser->append("Amount of " + comboBox_medication->currentText() + " medication: " + QString::number(numMedication));
  35. textBrowser->append("Cost of medication: " + QString::number(P.getTotalPharmacyCost()));
  36. textBrowser->append("Total cost of hospitalstay: " + QString::number(PA.getTotalCharges()));
  37. }
  38.  
  39. void Oppg2::clear()
  40. {
  41. spinBox_days->setValue(0);
  42. spinBox_surgery->setValue(0);
  43. spinBox_medication->setValue(0);
  44. textBrowser->clear();
  45. }
  46.  
  47. //End Oppg2 class
  48.  
  49. //Start PatientAccount class
  50.  
  51. void PatientAccount::setDaysInHospital(int daysInHospital)
  52. {
  53. daysInHospital=spinBox_days->value();
  54. }
  55.  
  56. void PatientAccount::setDaysInHospitalCost(int daysInHospitalCost)
  57. {
  58. daysInHospitalCost=daysInHospital*dailyRate;
  59. }
  60.  
  61. void PatientAccount::setTotalCharges(int totalCharges)
  62. {
  63. Surgery S;
  64. int gTSC=S.getTotalSurgeryCost();
  65. Pharmacy P;
  66. int gTPC=P.getTotalPharmacyCost();
  67. totalCharges=(daysInHospitalCost+gTSC+gTPC);
  68. }
  69.  
  70. int PatientAccount::getDaysInHospitalCost()
  71. {
  72. return daysInHospitalCost;
  73. }
  74.  
  75. int PatientAccount::getTotalCharges()
  76. {
  77. return totalCharges;
  78. }
  79.  
  80. //End PatientAccount class
  81.  
  82. //Start Surgery class
  83.  
  84. void Surgery::setNumSurgery(int numSurgery)
  85. {
  86. numSurgery=spinBox_surgery->value();
  87. }
  88.  
  89. void Surgery::setSurgeryCost(int surgeryCost)
  90. {
  91. QString surgery;
  92.  
  93. surgery=comboBox_surgery->currentText();
  94.  
  95. if (surgery=="Brain") surgeryCost=220;
  96. else if (surgery=="Heart") surgeryCost=200;
  97. else if (surgery=="Eye") surgeryCost=90;
  98. else if (surgery=="Arm") surgeryCost=110;
  99. else if (surgery=="Leg") surgeryCost=120;
  100. }
  101.  
  102. void Surgery::setTotalSurgeryCost(int totalSurgeryCost)
  103. {
  104. totalSurgeryCost=(numSurgery)*(surgeryCost);
  105. }
  106.  
  107. int Surgery::getTotalSurgeryCost()
  108. {
  109. return totalSurgeryCost;
  110. }
  111.  
  112. //End Surgery class
  113.  
  114. //Start Pharmacy class
  115.  
  116. void Pharmacy::setNumMedication(int numMedication)
  117. {
  118. numMedication=spinBox_medication->value();
  119. }
  120.  
  121. void Pharmacy::setPharmacyCost(int pharmacyCost)
  122. {
  123.  
  124. QString medication;
  125.  
  126. medication=comboBox_medication->currentText();
  127.  
  128. if (medication=="Fentanyl") pharmacyCost=30;
  129. else if (medication=="Naproxen") pharmacyCost=15;
  130. else if (medication=="Oxycontin") pharmacyCost=35;
  131. else if (medication=="Valium") pharmacyCost=10;
  132. else if (medication=="Vicodin") pharmacyCost=25;
  133. }
  134.  
  135. void Pharmacy::setTotalPharmacyCost(int totalPharmacyCost)
  136. {
  137. totalPharmacyCost=(numMedication)*(pharmacyCost);
  138. }
  139.  
  140. int Pharmacy::getTotalPharmacyCost()
  141. {
  142. return totalPharmacyCost;
  143. }
  144.  
  145. //End Pharmacy class
To copy to clipboard, switch view to plain text mode 

All help appreciated, thanks.