[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How do I pass variables between functions?

Posted on 2011-10-02
33
Medium Priority
?
340 Views
Last Modified: 2012-05-12

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

0
Comment
Question by:mojeaux
  • 14
  • 11
  • 7
  • +1
33 Comments
 
LVL 7

Expert Comment

by:Bill Nolan
ID: 36900528
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;
}
0
 
LVL 32

Expert Comment

by:phoffric
ID: 36900623
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.
   
0
 
LVL 32

Expert Comment

by:phoffric
ID: 36900777
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.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 32

Accepted Solution

by:
phoffric earned 1000 total points
ID: 36900790
Naturally, before using any product from the web, you must scan it for viruses and check references to see if there are any issues with using it.

Re: your .pdb file, I found this link:
    http://social.msdn.microsoft.com/Forums/en-MY/vsdebug/thread/b80bd4bd-f820-4f8b-8495-d400cccfd0ee

In it, it says:
"On the Symbols page, go to the Symbol files (.pdb) locations box and select Microsoft Symbol Servers."

I looked at my settings in Visual Stdio 2010 Express, and the Microsoft Symbol Servers setting is unchecked; and since it works for me, I am leaving it alone as I am unfamiliar with this option.

To verify your configuration, create a new project in its own solution space and build/run a simple Hello World project. If that works, then you should be able to make progress on another project.

After getting your OP compiler errors (and warnings) fixed, then if there are still other problems, you can start a new project in its own workspace to see if that helps - others reported back that this suggestion worked for them.
0
 

Author Comment

by:mojeaux
ID: 36900908
As requested ... Here is a screen shot of the compiler errors:
 Compile errors
0
 

Author Comment

by:mojeaux
ID: 36900963
Ok, Here's what I have remaining.... Remaining compile Errors
0
 
LVL 32

Expert Comment

by:phoffric
ID: 36900977
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.
0
 

Author Comment

by:mojeaux
ID: 36900980
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

0
 
LVL 32

Expert Comment

by:phoffric
ID: 36901040
>>    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.
0
 

Author Comment

by:mojeaux
ID: 36901074
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.
0
 
LVL 13

Expert Comment

by:Hugh McCurdy
ID: 36901080
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?
0
 

Author Comment

by:mojeaux
ID: 36901081
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!
0
 
LVL 13

Expert Comment

by:Hugh McCurdy
ID: 36901087
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?

0
 

Author Comment

by:mojeaux
ID: 36901093
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?
0
 
LVL 13

Expert Comment

by:Hugh McCurdy
ID: 36901097
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).
0
 

Author Comment

by:mojeaux
ID: 36901100
Sorry!   Phoffric, you should have been included on the the thank you!... I appreciate you working with me as well.
0
 
LVL 13

Expert Comment

by:Hugh McCurdy
ID: 36901115
Could you please post a current copy of the code before referencing line numbers?  My copy has a comment on line 134.
0
 
LVL 32

Expert Comment

by:phoffric
ID: 36901127
>> 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.
0
 

Author Comment

by:mojeaux
ID: 36903046
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!
0
 
LVL 13

Expert Comment

by:Hugh McCurdy
ID: 36903171
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.  
0
 
LVL 32

Expert Comment

by:phoffric
ID: 36903249
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.
0
 
LVL 32

Expert Comment

by:phoffric
ID: 36903310
>> 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();
}
0
 
LVL 32

Expert Comment

by:phoffric
ID: 36903334
>> '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.
0
 

Author Comment

by:mojeaux
ID: 36907039
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

 compile errors
0
 
LVL 13

Expert Comment

by:Hugh McCurdy
ID: 36907187
I don't need to see the errors.  I'll just copy/paste your code and get the errors myself.
0
 
LVL 13

Assisted Solution

by:Hugh McCurdy
Hugh McCurdy earned 1000 total points
ID: 36907216
I only got one error on line 113.   113: error: 'CheckNo' undeclared (first use in this function)

CheckNo is not declared within the scope of CheckFees().  

How do you think you can let CheckFees() know the value of CheckNo?  Hint -- CheckFees() knows about CFees.

0
 

Author Comment

by:mojeaux
ID: 36907285
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... compile errors
0
 

Author Comment

by:mojeaux
ID: 36907346
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

compile errors
0
 

Author Comment

by:mojeaux
ID: 36907358
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.
0
 

Author Comment

by:mojeaux
ID: 36907384
Guess what I got!!!  A clean Compile!!!   Yeah Yall!!!   Thanks so much for your time!
0
 

Author Closing Comment

by:mojeaux
ID: 36907406
I appreciate the assistance  by HMCCURDY and by PHOFFRIC.   They were courteous and took the time to help explain the code.  Excellent Job guys!!
0
 
LVL 32

Expert Comment

by:phoffric
ID: 36907412
>> 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)?
0
 
LVL 32

Expert Comment

by:phoffric
ID: 36907420
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.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question