Link to home
Start Free TrialLog in
Avatar of mojeaux
mojeauxFlag for United States of America

asked on

How do I pass variables between functions?


Please see the code below... as you can probably see... I am a beginner.
I am having trouble compiling and running the code.
Even if it compiles, it will not debug ... get same errors... unable to open 'PDB' files and it
cant find the ntdll.dll, mscrv100d.dll, and another one...

However, I can compile/debug at the computer at work if needed.    

I'm having trouble with my logic and passing variable values between functions.
The character has been the main one... I've looked on the web, but have been unsecessful so far.

What am I doing wrong?   I would really appreciate someone to look over my code below and tell me
what I should be doing.    Thanks so much for the Assist!

#include <stdio.h>

#define CHKGACT	 15
#define MMKTACT              10


// FUNCTION DECLARATIONS

	void	GetAcctType(char AType);
	void  	GetNumberofChecks(int CheckNo);
                     void	ErrorMessage1(void);
	void	ErrorMessage2(void);
	void	ErrorMessage3(void);
	int  	CheckFees(int CheckNo, int CFees);
	void	TotalMonthlyFee(void);

int main(void)
{

// LOCAL DECLARATIONS
 
	char AType;		//Account Type
                     float  CheckNof;	//Number of checks
	float  CFees;		//Calculation of check fees based on CheckNo
	float  TMFee;  		//Total Monthly Fee
	char Cont;		//Continue with processing more accounts


// STATEMENTS

	GetAcctType(AType);
		if(AType == 'C' || AType == 'M')
		{
			GetNumberofChecks(&CheckNo);
			
				if(CheckNo < 0)
				{
				ErrorMessage2();
				getchar();
				return 0;
				}
				else
				{
                                                                                      CheckFees(CheckNo, CFees);
				TotalMonthlyFee(TMFee);
				}
		}
		else
		{
			printf("Would you like to calculate monthly fees for another account?  Please enter 'Y' or 'N':    ");
			scanf("%c", Cont);
				if (Cont == 'Y')
				{
				GetAcctType(&AType);
				}
				else
				{   
				printf("Thank you and Goodbye.\n");
				getchar();
				return 0;
				}
	}  
	getchar();
	return 0;


} // main


/* ~~~~~~~~~~~~~~~~~~ GetAcctType ~~~~~~~~~~~~~~~~~~~~~~
	This function reads a character response from the keyboard.
	Pre	    Parameter Atype is an address
	Post	Data read into parameter address
*/

void GetAcctType(char AType)
{
	printf("Please enter your account type -- 'C' for checking or 'M' for Money Market:     ");
	scanf("%c", AType);
	
	getchar();
	return;

}// GetAcctType


/* ~~~~~~~~~~~~~~~~~~ GetNumberofChecks ~~~~~~~~~~~~~~~~~~~~~~
	This function reads a integer response from the keyboard.
	Pre	    Parameter CheckNo is an address
	Post	Data read into parameter address
*/

void GetNumberofChecks(int* CheckNo)
{
	printf("Please enter the number of checks written for the month:     ");
	scanf("%d", &CheckNo);
	return;

}// GetNumberofChecks


/* ~~~~~~~~~~~~~~~~~~ CheckFees ~~~~~~~~~~~~~~~~~~~~~~
	This function calculates the check fee amount based on CheckNo.
	Pre	    Parameter CFees is an address
	Post	Data read into parameter address
*/

int CheckFees(int CheckNo, int* CFees)
{
	if(CheckNo < 20)
	{
		CFees = (CheckNo * .10);
	}
	else if(CheckNo >= 20 && CheckNo < 39)
	{
		CFees == (CheckNo * .08);
	}
	else if(CheckNo >= 40 && CheckNo < 59)
	{
		CFees == (CheckNo * .06);
	}
	else if(&CheckNo >= 60)
	{
		CFees == (CheckNo * .04);
    }
return;

}// GetAcctType


/* ~~~~~~~~~~~~~~~~~~ TotalMonthlyFee ~~~~~~~~~~~~~~~~~~~~~~
	This function calculates the total monthly fee amout.
	Pre	    Parameter MTFee is an address
	Post	Returns either (CheckFees + 10) or (Checkfees +15)
*/

void TotalMonthlyFee(void)
{

// LOCAL DECLARATIONS

int sum; 


// STATEMENTS


	if (AType == 'C')
	{
		sum = Cfees + CHKGACT;
		printf("The total monthly fee for your checking account is:  %d\n", sum);
	}
	else if (AType == 'M')
	{
		sum = CFees + MMKTACCT
		printf("The total monthly fee for your money market account is:  %d\n", sum);
	}
	else
	{
		ErrorMessage3(void);
	}

	return;

}// TotalMonthlyFee


/* ~~~~~~~~~~~~~~~~~~ Error Message1 ~~~~~~~~~~~~~~~~~~~~~~
	This function displays an error message to the user.
	Pre	Parameter Msg1 is an address
	Post	Data read into parameter address
*/

void ErrorMessage1(void)
{

	printf("Your response was not valid.  Please try again and this time only enter 'C' for Checking account  or  'M' for Money Market account types.");
	return;

}// ErrorMessage1


/* ~~~~~~~~~~~~~~~~~~ Error Message2 ~~~~~~~~~~~~~~~~~~~~~~
	This function displays an error message to the user.
	Pre	Parameter Msg2 is an address
	Post	Data read into parameter address
*/

void ErrorMessage2(void)
{

	printf("Your response was not valid.  Please try again and this time enter a positive integer.");
	return;

}// ErrorMessage2


/* ~~~~~~~~~~~~~~~~~~ Error Message3 ~~~~~~~~~~~~~~~~~~~~~~
	This function displays an error message to the user.
	Pre	Parameter Msg3 is an address
	Post	Data read into parameter address
*/

void ErrorMessage2(void)
{

	printf("Could not process your request for monthly fee.  Please check your entries.");
	return;

}// ErrorMessage2

Open in new window

Avatar of Bill Nolan
Bill Nolan
Flag of United States of America image

You are passing 'AType' by value into GetAcctType.  Pass it by reference, or return the value from the function like this:

char GetAcctType()
{
        char AType;

      printf("Please enter your account type -- 'C' for checking or 'M' for Money Market:     ");
      scanf("%c", AType);
      
      return AType;
}
Avatar of phoffric
phoffric

line 34:   GetNumberofChecks(&CheckNo);
Your compiler should have told you what was wrong with this case. CheckNo is not defined in the main function.

As far as the .dll issues, that could mean system issues. Here's an article for you to consider to see if it may apply to you. If it does apply, then I suggest you ask a question in the Windows zone to get the best assistance.
   
I forgot to include the link for the .dll problem. Here it is:
    http://www.411pc.com/ntdll.dll/101/101167


Also, consider your declaration, definition, and usage of GetNumberofChecks:
Declaration:
   line 10:   void GetNumberofChecks(int CheckNo);
Usage:
   line 34:   GetNumberofChecks(&CheckNo);
Definition:
   line 93:   void GetNumberofChecks(int* CheckNo)

The declaration shows that GetNumberofChecks is expecting an int. But, your usage and definition indicate that a pointer to an int is expected. Again, your compiler should have given you an error identifying this problem.

My recommendation is that you look at the first compiler error that occurs, and try to fix it. If unable to do so, post the exact error message (and any new code), and we can help you through the compilation problems. Sometimes, an error is clarified by looking one or two message ahead; but often, other errors will go away after fixing the first error.
ASKER CERTIFIED SOLUTION
Avatar of phoffric
phoffric

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mojeaux

ASKER

As requested ... Here is a screen shot of the compiler errors:
 User generated image
Avatar of mojeaux

ASKER

Ok, Here's what I have remaining.... User generated image
Since the errors appear to be out of sync with the code in your OP, it is hard to help much. You'll have to post the actual code around the line number so that we have a common reference point.

But, one of the errors was complaining about >=. I search on >= to see whether there is something obvious and saw this:

line 122: else if(&CheckNo >= 60)

But comparing an address of an int to a literal int is not what you intended.

We should deal only with the first error. If you highlight the error and ctrl/C, then you may be able to post it, rather than post pictures of all the errors. After you fix an error with our help, this may assist you in figuring out your other compiler errors. If you run into trouble on a specific error, then explain what you do not understand, and we can try to help you.
Avatar of mojeaux

ASKER

The Error Message:
warning C4244: '=' : conversion from 'double' to 'int', possible loss of data

Where is it picking up that I'm trying to convert a double to an integer?
 
#include <stdio.h>
#include <math.h>

#define CHKGACT	 15.00
#define MMKTACT  10.00


// FUNCTION DECLARATIONS

	void	GetAcctType(char AType);
	void  	GetNumberofChecks(int* CheckNo);
    void	ErrorMessage1(void);
	void	ErrorMessage2(void);
	void	ErrorMessage3(void);
	int  	CheckFees(int* CFees);
	void	TotalMonthlyFee(int* TMFee);

//GLOBAL DECLARATIONS

	char AType;		    //Account Type
    int  CheckNo;    	//Number of checks
	int  CFees;	        //Calculation of check fees based on CheckNo
	int  TMFee;         //Total Monthly Fee
	char Cont;		    //Continue with processing more accounts

int main(void)
{

// STATEMENTS

	GetAcctType(AType);
		if(AType == 'C' || AType == 'M')
		{
			GetNumberofChecks(&CheckNo);
			
				if(CheckNo < 0)
				{
				ErrorMessage2();
				system(pause);
				return 0;
				}
				else
				{
                CheckFees(&CFees);
				TotalMonthlyFee(&TMFee);
				}
		}
		else
		{
			printf("Would you like to calculate monthly fees for another account?  Please enter 'Y' or 'N':    ");
			scanf("%c", Cont);
				if (Cont == 'Y')
				{
				GetAcctType(&AType);
				}
				else
				{   
				printf("Thank you and Goodbye.\n");
				system(pause);
				return 0;
				}
	}  
    system(pause);
	return 0;


} // main


/* ~~~~~~~~~~~~~~~~~~ GetAcctType ~~~~~~~~~~~~~~~~~~~~~~
	This function reads a character response from the keyboard.
	Pre	    Parameter Atype is an address
	Post	Data read into parameter address
*/

void GetAcctType(char AType)
{
	printf("Please enter your account type -- 'C' for Checking or 'M' for Money Market:     ");
	scanf("%c", AType);
	
	return;

}// GetAcctType


/* ~~~~~~~~~~~~~~~~~~ GetNumberofChecks ~~~~~~~~~~~~~~~~~~~~~~
	This function reads a integer response from the keyboard.
	Pre	    Parameter CheckNo is an address
	Post	Data read into parameter address
*/

void GetNumberofChecks(int* CheckNo)
{
	printf("Please enter the number of checks written for the month:     ");
	scanf("%i", &CheckNo);

	return;

}// GetNumberofChecks


/* ~~~~~~~~~~~~~~~~~~ CheckFees ~~~~~~~~~~~~~~~~~~~~~~
	This function calculates the check fee amount based on CheckNo.
	Pre	    Parameter CFees is an address
	Post	Data read into parameter address
*/

int CheckFees(int* CFees)
{
	if(CheckNo < 20)
	{
		*CFees = (CheckNo * .10);
	}
	else if(CheckNo >= 20 && CheckNo < 39)
	{
		*CFees = (CheckNo * .08);
	}
	else if(CheckNo >= 40 && CheckNo < 59)
	{
		*CFees = (CheckNo * .06);
	}
	else if(CheckNo >= 60)
	{
		*CFees = (CheckNo * .04);
    }
return;

}// GetAcctType


/* ~~~~~~~~~~~~~~~~~~ TotalMonthlyFee ~~~~~~~~~~~~~~~~~~~~~~
	This function calculates the total monthly fee amout.
	Pre	    Parameter MTFee is an address
	Post	Returns either (CheckFees + 10) or (Checkfees +15)
*/

void TotalMonthlyFee(int* TMFee);
{

	if (AType == 'C')
	{
		*TMFee = Cfees + CHKGACT;
		printf("The total monthly fee for your checking account is:  %9.2d\n", *TMFee);
	}
	else if (AType == 'M')
	{
		*TMFee = CFees + MMKTACCT;
		printf("The total monthly fee for your money market account is:  %9.2d\n", *TMFee);
	}
	else
	{
		ErrorMessage3();
	}

	return;

}// TotalMonthlyFee


/* ~~~~~~~~~~~~~~~~~~ Error Message1 ~~~~~~~~~~~~~~~~~~~~~~
	This function displays an error message to the user.
	Pre	Parameter Msg1 is an address
	Post	Data read into parameter address
*/

void ErrorMessage1(void)
{

	printf("Your response was not valid.  Please try again and this time only enter 'C' for Checking account  or  'M' for Money Market account types.");
	return;

}// ErrorMessage1


/* ~~~~~~~~~~~~~~~~~~ Error Message2 ~~~~~~~~~~~~~~~~~~~~~~
	This function displays an error message to the user.
	Pre	Parameter Msg2 is an address
	Post	Data read into parameter address
*/

void ErrorMessage2(void)
{

	printf("Your response was not valid.  Please try again and this time enter a positive integer.");
	return;

}// ErrorMessage2


/* ~~~~~~~~~~~~~~~~~~ Error Message3 ~~~~~~~~~~~~~~~~~~~~~~
	This function displays an error message to the user.
	Pre	Parameter Msg3 is an address
	Post	Data read into parameter address
*/

void ErrorMessage2(void)
{

	printf("Could not process your request for monthly fee.  Please check your entries.");
	return;

}// ErrorMessage2

Open in new window

>>    warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
compiler warnings and errors have line numbers. What line number in your http:#36900980 code post

You don't have float or double in your latest listing, but you do have:
#define CHKGACT  15.00
#define MMKTACT  10.00

You might want to focus on the error messages, rather than warning, just to get a program that you can run and debug. After correcting the errors, then focus on the warnings.
Avatar of mojeaux

ASKER

I was focusing on the error messages... this one happened to be linked to the three warnings...

c(134): warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
c(138): warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
c(142): warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
c(146): warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
c(148): warning C4033: 'CheckFees' must return a value
c(164): error C2065: 'Cfees' : undeclared identifier

I was working on the error msg for lines 148 and 164... I think these are a result of not being able to convert data types in the previous warning msgs.
This appears to be homework or self learning.  In that case, I'll focus on trying to help you to learn.

I attempted to compile the most recent copy of code that you posted.  (The 39 in the example means line 39).

39: error: 'pause' undeclared (first use in this function)

The problem here is the compiler is looking for a variable called pause.  However, I doubt you meant to have a variable called pause.
When an argument isn't in quotes, it's a variable.  When it's in quotes, it's a string constant.  You want

system ( "pause" );

Does that make sense?
Avatar of mojeaux

ASKER

Also, I removed my define statements and replaced them with global variables:

const int MCFee = 15;
const int MMFee = 10;

Thanks for your assistance tonight!   I really appreciate the help!
Before I continue, look at line 202 and decide if that's really the comment you want on that line.  (I still make that mistake sometimes.  Don't feel bad.)

54: warning: passing argument 1 of 'GetAcctType' makes integer from pointer without a cast

OK, let's look at line 54

GetAcctType(&AType);

However, here's the definition   void    GetAcctType(char AType);

The argument for GetAcctType should be a character.  AType isn't a character and the address of AType most certainly isn't a character.

What do you think you should do instead?

Avatar of mojeaux

ASKER

Thank you hmccurdy... I corrected the pause statements as described and it removed the compiler errors.   The explanation was very helpful too.  

(134): warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
c(138): warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
c(142): warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
c(146): warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
c(148): warning C4033: 'CheckFees' must return a value
c(164): error C2065: 'Cfees' : undeclared identifier

Still working on the last problem child function... not sure where I'm trying to convert dbl to int...
Will continue to took.   Any ideas?
Clearly you are working on the code right now.  Please fix what you can and post your code again.  (Please post your entire code each time so I can copy/paste it and compile it on my computer).
Avatar of mojeaux

ASKER

Sorry!   Phoffric, you should have been included on the the thank you!... I appreciate you working with me as well.
Could you please post a current copy of the code before referencing line numbers?  My copy has a comment on line 134.
>> Sorry!   Phoffric, you ...
Not an issue. It's good that hmccurdy has joined in to help, as I will have little time tonight (but I'll definitely be back tomorrow to help get these compiler errors squared away).

One comment about lines 142 and 147.
>> 'Cfees' : undeclared identifier

Notice that you have a global definition of 'CFees', which has a capital 'F'. Looks like a simple typo to me. Remember that C is case-sensitive.

BTW - I would consider two things to help your coding. (1) Try to avoid global variables. (2) Try to avoid the same variable name used by the caller and the callee - maybe a minor change in the spelling in the called function.

See you tomorrow. Good luck.
Avatar of mojeaux

ASKER

Hi All - just checking in.   Good catch on the typo!  I will look at this when I get home this afternoon.

If you dont mind me asking, but why should global variables be avoided?  Would moving these variables to the main function be a better option, or should they be moved locally where the fuctions are defined?    Also, I thought that the variable name used by the calling and caller functions had to be the same.   If you use different names, wouldnt you then have to reassign the value to the variable in the calling function?

Thanks for everyone's time an efforst on this.   I will be posting the new code this afternoon.   Sorry for the delay but I am at work.  

See you this afternoon!  Thx!
Global variables have problems including

They can be changed by any function regardless of whether the function should be changing the variable.
The purpose of the variable is less clear when it's global.  If it's local to a function, then it's clear the variable is used by that function.
Two local variables in different functions can have the same name.  For instance, you might want an index called i in a for loop.  If i is declared globally instead of locally, if the function using i calls another function using i, i will likely be set to an unexpected value which is a program bug.
If you declare a variable both locally and globally, the local declaration will hide the global declaration.  You (or a maintenance programmer) might intend to update the global instance of the variable and end up updating the local instance instead.  Confusing program bug.

I'm sure there are more.  It sounds like you don't have any experience with Object Oriented Programming (OOP).  If you learn about OOP, you'll learn about a concept called encapsulation.  Encapsulation further protects local variables.  C++ is an OOP language that is an awful lot like C with extensions.  
There are many articles on the subject of global variables. Here is one:
    http://bytes.com/topic/c/insights/737451-case-against-global-variables

You can write a perfectly working piece of code using global variables. But, large projects tend to become costly to maintain if the number of global variables is not limited.
>> If you use different names, wouldnt you then have to reassign the value to the variable in the calling function?
Here's a simple example showing slightly different names for the same variable as you pass a variable into a function:

void f2( int * lineNum ) {
   *lineNum = 2;
}

void f1() {
  int line_number;
  f2( &line_number );
  printf("line # = %d\n", line_number);

}

int main() {
   f1();
}
>> 'Cfees' : undeclared identifier
>> Good catch on the typo!

Here is how to solve this. The compiler is telling you that you are using a variable 'Cfees' that has not been declared or defined in a line (or in a header file) above the point of use.

So, in your editor (or even in this IE8 browser), you can search for the 'Cfees' token and see where it is defined or declared with the match case option. Then you will not find its usage, but not find its declaration or definition.
Avatar of mojeaux

ASKER

Thank you for the information.   This has been a good learning experience.  

Moving the variables to the Main function has created a whole new set of comile issues. (sigh!)
Please see attached.    Here's the most recent copy of my code:

 
#include <stdio.h>
#include <math.h>

// FUNCTION DECLARATIONS

	void	GetAcctType(char AType);
	void  	GetNumberofChecks(int* CheckNo);
    void	ErrorMessage1(void);
	void	ErrorMessage2(void);
	void	ErrorMessage3(void);
	int  	CheckFees(int* CFees);
	void	TotalMonthlyFee(int* TMFee);

//GLOBAL DECLARATIONS



int main(void)
{

//LOCAL DECLARATIONS

	char AType;		    //Account Type
    int  CheckNo;    	//Number of checks
	int  CFees;	        //Calculation of check fees based on CheckNo
	int  TMFee;         //Total Monthly Fee
	char Cont;		    //Continue with processing more accounts
	int MCFee = 15;
	int MMFee = 10;

// STATEMENTS

	GetAcctType(AType);
		if(AType == 'C' || AType == 'M')
		{
			GetNumberofChecks(&CheckNo);
			
				if(CheckNo < 0)
				{
				ErrorMessage2();
//				system("pause");
				return 0;
				}
				else
				{
                CheckFees(&CFees);
				printf("Your Check Fees are:  \n", &CFees);
//				TotalMonthlyFee(&TMFee);
				}
		}
		else
		{
			printf("Would you like to calculate monthly fees for another account?  Please enter 'Y' or 'N':    ");
			scanf_s("%c", Cont);
				if (Cont == 'Y')
				{
				GetAcctType(AType);
				}
				else
				{   
				printf("Thank you and Goodbye.\n");
//				system("pause");
				return 0;
				}
	}  
//    system("pause");
	return 0;


} // main


/* ~~~~~~~~~~~~~~~~~~ GetAcctType ~~~~~~~~~~~~~~~~~~~~~~
	This function reads a character response from the keyboard.
	Pre	    Parameter Atype is an address
	Post	Data read into parameter address
*/

void GetAcctType(char AType)
{
	printf("Please enter your account type -- 'C' for Checking or 'M' for Money Market:     ");
	scanf_s("%c", AType);
	
	return;

}// GetAcctType


/* ~~~~~~~~~~~~~~~~~~ GetNumberofChecks ~~~~~~~~~~~~~~~~~~~~~~
	This function reads a integer response from the keyboard.
	Pre	    Parameter CheckNo is an address
	Post	Data read into parameter address
*/

void GetNumberofChecks(int* CheckNo)
{
	printf("Please enter the number of checks written for the month:     ");
	scanf_s("%i", &CheckNo);

	return;

}// GetNumberofChecks


/* ~~~~~~~~~~~~~~~~~~ CheckFees ~~~~~~~~~~~~~~~~~~~~~~
	This function calculates the check fee amount based on CheckNo.
	Pre	    Parameter CFees is an address
	Post	Data read into parameter address
*/

int CheckFees(int* CFees)
{
	if(CheckNo < 20)
	{
		*CFees = (CheckNo * .10);
	}
	else if(CheckNo >= 20 && CheckNo < 39)
	{
		*CFees = (CheckNo * .08);
	}
	else if(CheckNo >= 40 && CheckNo < 59)
	{
		*CFees = (CheckNo * .06);
	}
	else if(CheckNo >= 60)
	{
		*CFees = (CheckNo * .04);
    }
return;

}// GetAcctType


/* ~~~~~~~~~~~~~~~~~~ TotalMonthlyFee ~~~~~~~~~~~~~~~~~~~~~~
	This function calculates the total monthly fee amout.
	Pre	    Parameter MTFee is an address
	Post	Returns either (CheckFees + 10) or (Checkfees +15)
*/

/*void TotalMonthlyFee(int* TMFee)
{
    if (AType == 'C')
	{
		*TMFee = CFees + MCFee;
		printf("The total monthly fee for your checking account is:  %9.2d\n", *TMFee);
	}
	else if (AType == 'M')
	{
		*TMFee = CFees + MMFee;
		printf("The total monthly fee for your money market account is:  %9.2d\n", *TMFee);
	}
	else
	{
		ErrorMessage3();
	}

	return;

}// TotalMonthlyFee*/


/* ~~~~~~~~~~~~~~~~~~ Error Message1 ~~~~~~~~~~~~~~~~~~~~~~
	This function displays an error message to the user.
	Pre	Parameter Msg1 is an address
	Post	Data read into parameter address
*/

void ErrorMessage1(void)
{

	printf("Your response was not valid.  Please try again and this time only enter 'C' for Checking account  or  'M' for Money Market account types.");
	return;

}// ErrorMessage1


/* ~~~~~~~~~~~~~~~~~~ Error Message2 ~~~~~~~~~~~~~~~~~~~~~~
	This function displays an error message to the user.
	Pre	Parameter Msg2 is an address
	Post	Data read into parameter address
*/

void ErrorMessage2(void)
{

	printf("Your response was not valid.  Please try again and this time enter a positive integer.");
	return;

}// ErrorMessage2


/* ~~~~~~~~~~~~~~~~~~ Error Message3 ~~~~~~~~~~~~~~~~~~~~~~
	This function displays an error message to the user.
	Pre	Parameter Msg3 is an address
	Post	Data read into parameter address
*/

void ErrorMessage3(void)
{

	printf("Could not process your request for monthly fee.  Please check your entries.");
	return;

}// ErrorMessage3

Open in new window

 User generated image
I don't need to see the errors.  I'll just copy/paste your code and get the errors myself.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mojeaux

ASKER

Do I need to declare CheckNo as a local variable to the function CheckFees()?   And if I do, I get a whole other set of compile errors... User generated image
Avatar of mojeaux

ASKER

Ok... I changed things up... I'm chaning my functions to pass by value rather than pass by reference... see code below.   I've attached compile errors below that...   Seems like fewer errors.  
How do I initialize my local variables?
Why does it tell me that a void function is returning a value?  I thought the void referred to the incoming data to the function.. or data that it was receiving.. not what it was passing.

Thanks so much for your time!   You have been a great help!!
#include <stdio.h>
#include <math.h>

// FUNCTION DECLARATIONS

	void	GetAcctType(char AType);
	void  	GetNumberofChecks(float CheckNo);
    void	ErrorMessage1(void);
	void	ErrorMessage2(void);
	void	ErrorMessage3(void);
	void  	CheckFees(float CFees);
	void	TotalMonthlyFee(int TMFee);

//GLOBAL DECLARATIONS



int main(void)
{

//LOCAL DECLARATIONS

	char AType;		    //Account Type
    float  CheckNo;    	//Number of checks
	float  CFees;	        //Calculation of check fees based on CheckNo
//	int  TMFee;         //Total Monthly Fee
	char Cont;		    //Continue with processing more accounts
	int MCFee = 15;
	int MMFee = 10;

// STATEMENTS

	GetAcctType(AType);
		if(AType == 'C' || AType == 'M')
		{
			GetNumberofChecks(CheckNo);
			
				if(CheckNo < 0)
				{
				ErrorMessage2();
//				system("pause");
				return 0;
				}
				else
				{
                CheckFees(CFees);
				printf("Your Check Fees are:  \n", CFees);
//				TotalMonthlyFee(TMFee);
				}
		}
		else
		{
			printf("Would you like to calculate monthly fees for another account?  Please enter 'Y' or 'N':    ");
			scanf_s("%c", Cont);
				if (Cont == 'Y')
				{
				GetAcctType(AType);
				}
				else
				{   
				printf("Thank you and Goodbye.\n");
//				system("pause");
				return 0;
				}
	}  
//    system("pause");
	return 0;


} // main


/* ~~~~~~~~~~~~~~~~~~ GetAcctType ~~~~~~~~~~~~~~~~~~~~~~
	This function reads a character response from the keyboard.
	Pre	    Parameter Atype is an address
	Post	Data read into parameter address
*/

void GetAcctType(char AType)
{
	printf("Please enter your account type -- 'C' for Checking or 'M' for Money Market:     ");
	scanf_s("%c", AType);
	
	return;

}// GetAcctType


/* ~~~~~~~~~~~~~~~~~~ GetNumberofChecks ~~~~~~~~~~~~~~~~~~~~~~
	This function reads a integer response from the keyboard.
	Pre	    Parameter CheckNo is an address
	Post	Data read into parameter address
*/

void GetNumberofChecks(float CheckNo)
{
	printf("Please enter the number of checks written for the month:     ");
	scanf_s("%i", CheckNo);

	return CheckNo;

}// GetNumberofChecks


/* ~~~~~~~~~~~~~~~~~~ CheckFees ~~~~~~~~~~~~~~~~~~~~~~
	This function calculates the check fee amount based on CheckNo.
	Pre	    Parameter CFees is an address
	Post	Data read into parameter address
*/

void CheckFees(float CFees)
{
	float CheckNo;

	if(CheckNo < 20)
	{
		CFees = (CheckNo * .10f);
	}
	else if(CheckNo >= 20 && CheckNo < 39)
	{
		CFees = (CheckNo * .08f);
	}
	else if(CheckNo >= 40 && CheckNo < 59)
	{
		CFees = (CheckNo * .06f);
	}
	else if(CheckNo >= 60)
	{
		CFees = (CheckNo * .04f);
    }
return;

}// GetAcctType


/* ~~~~~~~~~~~~~~~~~~ TotalMonthlyFee ~~~~~~~~~~~~~~~~~~~~~~
	This function calculates the total monthly fee amout.
	Pre	    Parameter MTFee is an address
	Post	Returns either (CheckFees + 10) or (Checkfees +15)
*/

/*void TotalMonthlyFee(int* TMFee)
{
    if (AType == 'C')
	{
		*TMFee = CFees + MCFee;
		printf("The total monthly fee for your checking account is:  %9.2d\n", *TMFee);
	}
	else if (AType == 'M')
	{
		*TMFee = CFees + MMFee;
		printf("The total monthly fee for your money market account is:  %9.2d\n", *TMFee);
	}
	else
	{
		ErrorMessage3();
	}

	return;

}// TotalMonthlyFee*/


/* ~~~~~~~~~~~~~~~~~~ Error Message1 ~~~~~~~~~~~~~~~~~~~~~~
	This function displays an error message to the user.
	Pre	Parameter Msg1 is an address
	Post	Data read into parameter address
*/

void ErrorMessage1(void)
{

	printf("Your response was not valid.  Please try again and this time only enter 'C' for Checking account  or  'M' for Money Market account types.");
	return;

}// ErrorMessage1


/* ~~~~~~~~~~~~~~~~~~ Error Message2 ~~~~~~~~~~~~~~~~~~~~~~
	This function displays an error message to the user.
	Pre	Parameter Msg2 is an address
	Post	Data read into parameter address
*/

void ErrorMessage2(void)
{

	printf("Your response was not valid.  Please try again and this time enter a positive integer.");
	return;

}// ErrorMessage2


/* ~~~~~~~~~~~~~~~~~~ Error Message3 ~~~~~~~~~~~~~~~~~~~~~~
	This function displays an error message to the user.
	Pre	Parameter Msg3 is an address
	Post	Data read into parameter address
*/

void ErrorMessage3(void)
{

	printf("Could not process your request for monthly fee.  Please check your entries.");
	return;

}// ErrorMessage3

Open in new window

User generated image
Avatar of mojeaux

ASKER

One other comment, I changed the two variables (GetNumberofChecks() and CheckFees()) to float types and it worked but left me with the uninitiated varialble compile errors.
Avatar of mojeaux

ASKER

Guess what I got!!!  A clean Compile!!!   Yeah Yall!!!   Thanks so much for your time!
Avatar of mojeaux

ASKER

I appreciate the assistance  by HMCCURDY and by PHOFFRIC.   They were courteous and took the time to help explain the code.  Excellent Job guys!!
>> I'm changing my functions to pass by value rather than pass by reference
a) Why did you do that?
b) What do you think the implications of doing this is (in general)?
I see you just closed this question. But feel free to answer the Why and the What, and we'll make sure you understand what you need to understand with respect to your "pass by value rather than pass by reference" code change.