By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 943 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

need help... it keep warn me bout possible use and never used..

P: 1
Expand|Select|Wrap|Line Numbers
  1. #include<iostream.h>
  2. #include<conio.h>
  3.  
  4. void intro ();
  5. void input(int& , int& );
  6. float calculate1 ( int );
  7. float calculate2 (int , int );
  8. float calculate3 (int , int  );
  9. float calculate4 (int , int );
  10. void close (int , int , int ) ;
  11.  
  12. int main()
  13. {
  14.     int finance, month, totalMoney, totalMoneyMonth, spendMoney, useMonth, useDay, totalSave ;
  15.  
  16.  
  17. intro ();
  18.    input ( finance, month);
  19.    calculate1 ( month);
  20.    calculate2 ( totalMoneyMonth,  finance );
  21.    calculate3 ( totalMoney, totalSave);
  22.    calculate4 ( month, spendMoney);
  23.    close ( totalSave,  useMonth,  useDay);
  24.  
  25. getch ();
  26. return 0;
  27. }
  28.  
  29. void intro ()                                                                   //greeting the user
  30. {
  31.     cout<<"Hello there! Want to save money and help yourself to minimize money loss?"<<endl;
  32.    cout<<"If yes, please entered the question below."<<endl;
  33.    cout<<"We will be happy if this program will help you."<<endl;
  34.    cout<<"Thanks from us. - Hilal and Saffiq "<<endl;
  35. }
  36.  
  37. void input(int& finance, char& month)   //ask the user to enter basic question
  38. {
  39.    cout<<"Enter here if there any other finance you receive in one semester. E.g PTPTN : ";
  40.    cin>>finance;
  41.    cout<<"Enter how much month you want to be calculated : ";
  42.    cin>>month;
  43.  
  44. }
  45.  
  46. float calculate1 ( int month)    //finding the total saving and total money
  47. {
  48.     float totalMoneyMonth = 0, count = 1, pocket, totalSave = 0,save;
  49.  
  50.         while (count <= month);
  51.       {
  52.           cout<<" Enter the amount of money you receive in the "<<count<<" month : ";
  53.          cin>>pocket;
  54.          cout<<"How much money you want to save this month? : ";
  55.          cin>>save;
  56.          totalSave = totalSave + save;
  57.           totalMoneyMonth = totalMoneyMonth + pocket;
  58.          count++;
  59.       }
  60. return totalSave, totalMoneyMonth;
  61. }
  62.  
  63.  
  64. float calculate2 (int totalMoneyMonth, int finance )      //finding the total money the user have
  65. {
  66.     float totalMoney;
  67.     totalMoney = totalMoneyMonth + finance;
  68. return totalMoney;
  69. }
  70.  
  71.  
  72.  
  73. float calculate3 (int totalMoney, int totalSave)          //finding the total money the user can use
  74. {
  75.     float spendMoney =0 ;
  76.     spendMoney = totalMoney - totalSave;
  77.  
  78. return spendMoney;
  79. }
  80.  
  81.  
  82.  
  83. float calculate4 (int month, int spendMoney)        //finding the total money the user can use
  84. {
  85.     int days = 180, useDay, useMonth;
  86.     useMonth = spendMoney / month;
  87.    useDay = spendMoney / days;
  88. return useDay, useMonth;
  89. }
  90. void close (int totalSave, int useMonth, int useDay)                       //tell the user about the result
  91. {
  92.     cout<<"The money you can save for this semester is : "<<totalSave<<endl;
  93.    cout<<"You have this amount of money in a month to achieve the saving : "<<useMonth<<endl;
  94.    cout<<"You have to spend this amount of money for a day : "<<useDay<<endl;
  95. }
  96.  
Mar 10 '17 #1
Share this Question
Share on Google+
3 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
None of your variables are initialized before you use them. That means you can't trust your results.

Initialize all your float variables to 0.0 and all of your int variables to 0 before you use any of them.
Mar 10 '17 #2

dev7060
P: 62
Here are the few things I noticed:

1: On line 37, change 'char &month' to 'int &month'.
2: On line 60 and 88, the functions are trying to return more than one values. A function can return only one value.
[ left operand of comma operator has no effect [-Wunused-value] ]
3: As mentioned by @weaknessforcats, initialise the variables.

Also, try to mention some theoretical concept of the program as by that it would be easy for others to analyse the program well.
Mar 12 '17 #3

dev7060
P: 62
Here are the few things I noticed:

1: On line 37, change 'char &month' to 'int &month'.
2: On line 60 and 88, the functions are trying to return more than one values. A function can return only one value.
[ left operand of comma operator has no effect [-Wunused-value] ]
3: As mentioned by @weaknessforcats, initialise the variables.

Also, try to mention some theoretical concept of the program as by that, it would be easy for others to analyse the program well.
Mar 12 '17 #4

Post your reply

Sign in to post your reply or Sign up for a free account.