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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • muisye
    New Member
    • Mar 2017
    • 1

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

    Code:
    #include<iostream.h>
    #include<conio.h>
    
    void intro ();
    void input(int& , int& );
    float calculate1 ( int );
    float calculate2 (int , int );
    float calculate3 (int , int  );
    float calculate4 (int , int );
    void close (int , int , int ) ;
    
    int main()
    {
    	int finance, month, totalMoney, totalMoneyMonth, spendMoney, useMonth, useDay, totalSave ;
    
    	
    intro ();
       input ( finance, month);
       calculate1 ( month);
       calculate2 ( totalMoneyMonth,  finance );
       calculate3 ( totalMoney, totalSave);
       calculate4 ( month, spendMoney);
       close ( totalSave,  useMonth,  useDay);
    
    getch ();
    return 0;
    }
    
    void intro ()                                                                   //greeting the user
    {
    	cout<<"Hello there! Want to save money and help yourself to minimize money loss?"<<endl;
       cout<<"If yes, please entered the question below."<<endl;
       cout<<"We will be happy if this program will help you."<<endl;
       cout<<"Thanks from us. - Hilal and Saffiq "<<endl;
    }
    
    void input(int& finance, char& month)   //ask the user to enter basic question
    {
       cout<<"Enter here if there any other finance you receive in one semester. E.g PTPTN : ";
       cin>>finance;
       cout<<"Enter how much month you want to be calculated : ";
       cin>>month;
    
    }
    
    float calculate1 ( int month)    //finding the total saving and total money
    {
    	float totalMoneyMonth = 0, count = 1, pocket, totalSave = 0,save;
    
    		while (count <= month);
          {
          	cout<<" Enter the amount of money you receive in the "<<count<<" month : ";
             cin>>pocket;
             cout<<"How much money you want to save this month? : ";
             cin>>save;
             totalSave = totalSave + save;
          	totalMoneyMonth = totalMoneyMonth + pocket;
             count++;
          }
    return totalSave, totalMoneyMonth;
    }
    
    
    float calculate2 (int totalMoneyMonth, int finance )      //finding the total money the user have
    {
    	float totalMoney;
    	totalMoney = totalMoneyMonth + finance;
    return totalMoney;
    }
    
    
    
    float calculate3 (int totalMoney, int totalSave)          //finding the total money the user can use
    {
    	float spendMoney =0 ;
    	spendMoney = totalMoney - totalSave;
    
    return spendMoney;
    }
    
    
    
    float calculate4 (int month, int spendMoney)        //finding the total money the user can use
    {
    	int days = 180, useDay, useMonth;
    	useMonth = spendMoney / month;
       useDay = spendMoney / days;
    return useDay, useMonth;
    }
    void close (int totalSave, int useMonth, int useDay)                       //tell the user about the result
    {
    	cout<<"The money you can save for this semester is : "<<totalSave<<endl;
       cout<<"You have this amount of money in a month to achieve the saving : "<<useMonth<<endl;
       cout<<"You have to spend this amount of money for a day : "<<useDay<<endl;
    }
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    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.

    Comment

    • dev7060
      Recognized Expert Contributor
      • Mar 2017
      • 656

      #3
      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 @weaknessforcat s, 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.

      Comment

      • dev7060
        Recognized Expert Contributor
        • Mar 2017
        • 656

        #4
        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 @weaknessforcat s, 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.

        Comment

        Working...