Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Leanna

Help with Functions

This topic is 5131 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello! I''ve been working on a program assignment for hours now and can''t figure out what''s wrong with it and I''m becoming extremely frustrated!!! The compiler says there are no errors as is, but when I run it, the functions that I''m trying to call don''t work. Any help? (Go easy on me- I''m barely a beginner!) #include <stdlib.h> #include <iostream.h> #include <conio.h> // Funtion Prototypes // double CalcSavings (double principal, double real_rate, long num_years); void ReportFindings (double principal, double rate, long num_years, double savings); double CalcSavings (double principal, double real_rate, long num_years) { if (num_years == 0) return 1; if (num_years == 1) return principal; else { int counter; double savings= principal; for (counter = 0; counter < num_years - 1; counter++) savings = principal *( 1 + real_rate); return savings; } } void ReportFindings (double principal, double real_rate, long num_years, double savings) { cout << "Based on your initial investment of:" << principal << endl ; cout << "and an annual return rate of :" << real_rate << endl; cout << "for " << num_years << "years, the total return is:" << savings << endl; } int main () { int sims; double principal, real_rate, savings; long num_years; cout << "How many simulations would you like me to complete?"; cin >> sims; int counter; for (counter = 0; counter <= sims -1; counter++) { cout << "Please enter your principal:"; cin >> principal; cout << "Please enter annual interest rate:"; cin >> real_rate; cout << "Please enter the number of years:"; cin >> num_years; if (( principal < 0) || ( real_rate < 0) || (num_years < 0)) cout << "I''m sorry, you have entered an illegal input parameter." <

Share this post


Link to post
Share on other sites
Advertisement
You are calling your functions wrongly in your main program. You''re just declaring them again, when in fact you need to call them.

Don''t redefine the arguments in your function, replace them with the variables you got from the user, via cin.

Where you have
double CalcSavings (double principal, double real_rate, long num_years);

call it just by using
functionname(arguments,...)

So you''d do
CalcSavings(principal, real_rate, num_years);

Your other function you need to modify in a similar way.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!