I'm missing some key basic concepts here that I thought I understood with functions, pass by value, pass by reference. I tried deleting most of my parameters, to no avail, I took out my multiple returns, and fooled around with pass by reference.....I keep getting an address for my min_payment output...I REALLY NEED to understand this as I am coming close to class beginning and it focuses on debugging and depends on a good foundation in the basics. I read my text from last semester, but it often gets me confused:

#include <iostream>
using namespace std;

		double  balance, balance1, balance2, payment, total_due1;

		double rate_maker(double balance1, double balance2, double& total_due1);
		double min_payment(double payment,double& total_due1);


		double rate_maker(double balance1, double balance2, double& total_due1)
	{
		
		
			if(balance <= 1000)
		{
			balance1 = balance * .015;
			total_due1 = balance1;
		
		}

			else if(balance > 1000)
		{
			balance1 = (1000 * .015);
			balance2 = (balance - 1000 * .01);
			total_due1 = balance1 + balance2;
			return total_due1;
				
			
		}
		
	}

		double min_payment(double payment, double& total_due1)

	{
		if(total_due1 <= 10)
		{
			payment = total_due1;
		
		}
		else if(10 < total_due1 * .01)
		{
			payment = total_due1 * .01;
			
			
		}
		else
		{
			payment = 10;
			return payment;
		}
	}


	int main()
	{
		double interest, monthly, owed, bal1=0, bal2=0, pay=0;

		cout << "Please enter your current balance: " << endl;
		cin >> balance;
		interest = rate_maker(bal1,bal2,owed);
		cout << "Your total due is: " << interest << endl;
		
		monthly = min_payment(pay,owed);
		cout <<"Your monthly payment is: " << monthly << endl;

		int x;
		cin >> x;

		return 0;
	}

I ran it just now for balance = 100
They're not addresses, they're numbers in scientific notation.

Basically, not all paths in your functions return values. So for some values (e.g. 100) your function isn't returning anything, which results in weird behaviour and large, meaningless numbers as a consequence.

Try taking the "return" lines outside of the if/elseif/else blocks (see below), or just make sure to provide a return value in every block.

e.g.

#include <iostream>
using namespace std;

		double  balance, balance1, balance2, payment, total_due1;

		double rate_maker(double balance1, double balance2, double& total_due1);
		double min_payment(double payment,double& total_due1);


		double rate_maker(double balance1, double balance2, double& total_due1)
	{
		
		
			if(balance <= 1000)
		{
			balance1 = balance * .015;
			total_due1 = balance1;
		
		}

			else if(balance > 1000)
		{
			balance1 = (1000 * .015);
			balance2 = (balance - 1000 * .01);
			total_due1 = balance1 + balance2;
			
				
			
		}
		return total_due1;
	}

		double min_payment(double payment, double& total_due1)

	{
		if(total_due1 <= 10)
		{
			payment = total_due1;
		
		}
		else if(10 < total_due1 * .01)
		{
			payment = total_due1 * .01;
			
			
		}
		else
		{
			payment = 10;
			
		}
return payment;
	}


	int main()
	{
		double interest, monthly, owed, bal1=0, bal2=0, pay=0;

		cout << "Please enter your current balance: " << endl;
		cin >> balance;
		interest = rate_maker(bal1,bal2,owed);
		cout << "Your total due is: " << interest << endl;
		
		monthly = min_payment(pay,owed);
		cout <<"Your monthly payment is: " << monthly << endl;

		int x;
		cin >> x;

		return 0;
	}

Try taking the "return" lines outside of the if/elseif/else blocks.....
tHAT'S GOT it phalaris_trip! I kept putting my returns inside my definitions

It must be in your definition, yes.
It just has to return something (something valid) regardless of what logical path the function takes.

Hope I didn't confuse you even more.. :/

Actually i am not getting what exactly your problem is? but i read your program and i found that there are a lots of loopholes...and i must not give you the required result...so tell me if it is working...

You are having a lots of unnecessary vairables and if clauses...
for example you dont need to have any global variable and you should not have global variables untill unless it is must.
you dont need if clause in line 21..
and the biggest problem i think is that...you are returning the values from the function in one of the else or if clause(line no 26 and 50)...now tell me what value it will returns if that if/else is not being executed..

please clearly state your problem...

I ran it just now for balance = 100
They're not addresses, they're numbers in scientific notation

i am not getting even those...i m getting simple integers 0 or some calculated value....

>>tHAT'S GOT it phalaris_trip! I kept putting my returns inside my definitions

I guess you must be one of those people who have to be hit over the head with a brick before you understand what you read. Nurue and I told you that two hours ago in your other thread.

i am not getting even those...i m getting simple integers 0 or some calculated value....

When the programmer leaves out the return statement in a function that expects a return, and IGNORES all compiler's warnings, then what you experienced is called undefined behavior meaning that the results may be compiler dependent, and may even change when running the same program at different times.

This article has been dead for over six months. Start a new discussion instead.