Monday, May 24, 2010

Help me in my c++ program?

could any one found the error ?





#include%26lt;iostream%26gt;


using namespace std;





double bank (double principle,double year ,double rate )


{


cout%26lt;%26lt;"enter ur principle , please \n";





cin%26gt;%26gt;principle;





cout%26lt;%26lt;"enter how many years u put this principle , please \n";





cin%26gt;%26gt;year;





rate= (principle +year*0.06);





return rate;





}


int main()


{


bank();





return 0;


}

Help me in my c++ program?
You are not passing any parameters/arguements while making a call to bank() ....


replace bank(); with bank(1000,2,3);


that ought do the trick
Reply:You don't need the parameter if you are asking for the values in the function your called from main is right you just need to take out the parameters from the function. Also if you want this code to be safe you need to make sure the user is input is a numeric value.
Reply:You're calling bank without any arguments. I hope you aren't planning on handing this in with "ur" and "u" in the output.
Reply:#include %26lt;iostream%26gt;


using namespace std;





/*if you put arguments in a function, it means you have to insert those arguments from 'the outside' of the function in order for the functions to work. In your case, you don't need arguments, since the inputted variables come from the inside of the function. */





double bank(){


double principle;


double year;


double rate;





cout%26lt;%26lt;"enter ur principle , please \n";


cin%26gt;%26gt;principle;


cout%26lt;%26lt;"enter how many years u put this principle , please \n";


cin%26gt;%26gt;year;





rate= (principle +year*0.06);


return rate;





}





int main(){


bank();


return 0;


}


No comments:

Post a Comment