Big Racket Function Problem

I have been working this problem for 2 days now, I know I am a novice but it's killing me, I have attached my code and still can't get it all to work. I haven't finished answering all of it cause I can't get it to compile using a simple if statement of "F" and "5" (once you read the question it may seem more clear)

The program should prompt the user for the membership type (F for Familiy and I for Individual) and the number of years the person has been a member. Use a function Get_Member_Type() that prompts the user for his membership type. Use a function Years() that prompts for the number of years, return both to main(). Use Function Dues() to calculate members dues as follows:
Family and <3 years dues = 3000
Family and >3 years dues = 2400
Individual <5 years dues = 1900
Individual >5 years dues = 3000
Use a function Display_Member_Info() to display type of membership, number of years, due amount...pass everything as functions back to main!

MY CODE THUS FAR along with a photo of the error

#include "stdafx.h"
#include "iomanip"
#include "iostream"

using namespace std;

char Get_Member_Type ();
int Get_Years ();
double Get_Dues ();
//void Display_Member_Info ();

int main()
{
char Member_Type;
int Years;
double Dues;

// Obtain Data

Member_Type = Get_Member_Type();
Years = Get_Years ();
Dues = Get_Dues ();

// Display Membership Type, Number of Years, and Dues

cout << endl;
cout << " Membership Type: " << Member_Type << endl;
cout << " Membership Years: " << Years << endl;
cout << " Your Dues are: $" << Dues << endl;

cout << endl;
system ("Pause");
return 0;
// End of Main

}
char Get_Member_Type ()
{
char Member_Type;
cout << " Enter your membership type followed by return. 'I' for Individual and 'F' for Family ";
cout << endl;
cin >> Member_Type;
return Member_Type;
}
int Get_Years ()
{
int Years;
cout << " Enter the number of years you have been a member " << endl;
cin >> Years;
return Years;
}
double Get_Dues ()
{
int Years;
char Member_Type;
int Dues;

if ((Member_Type = 'F') && (Years >= 3))
{
Dues = 2400;
}
else Dues = 0;
return Dues;
}

ERROR Runtime check failure #3 the varible "Years" is being used without being initialized
The problem is in your Get_Dues() funciton. The variables Member_Type and Years have not been initialized and your trying to use them in an if statement.

also, it should be Member_Type == 'F'

E: i hate when people give me vague answers like the one i gave, so ill give you a hint: Either pass Years and Member_Type in as arguments to the function, or make them global.
Last edited on
Nano
I don't want to use global varibles. Can you please elaborate a lil more, doesn't the Get_Years() Function return the Years to main for me? and the same with Get_Member_Type() function? How do I pass them back from main to Get_Dues()?
Ugh.

Please indent your code and use [code][/code] tags.

First:

1
2
3
#include "stdafx.h"
#include "iomanip"
#include "iostream" 


For header files that are in the include directory of the compiler, you need to use <angular brackets>: #include <iostream> , not "quotation marks". You can also turn off precompiled headers or just create an empty project or something like that (I usually just tell it not to use them).

After fixing that, it compiled for me. When I type in 'I' at over 5 years, I got $2400. Here's where I think you went wrong:

if ((Member_Type = 'F') && (Years >= 3))

a) if (var == val)

A single = sign signifies assignment, double == is a conditional operator. That is what you should use (someone already covered this, but I'm really slow at typing, so I have to reload the page after typing this all out to see if someone beat me to something, so I will give nano511 the credit here)

b) You never tell it anything else, you merely check to see if it is a family or not, then give one of two values, as opposed to the four that you give at the start.

You also fail to ensure that the user enters 'I' or 'F'. If I type in 'r' at one year, I get $2400.

There are more issues (nano511 covered some and I'll let him/ her cover the global variable/ function argument thing), but I really think you should try and figure it out, that's usually the best part (for me), sitting down and hammering out why it won't work. It's also better to learn how to solve problems on your own, especially if you plan on making a living doing it (any field of work, computers, the automotive industry, carpentry, plumbing etc...). Otherwise your boss will laugh at how useless you are and fire your ass. Try compiling it, read (and understand to the best of your ability) the compiler errors and warning, find what is causing the error/ warning (I try to avoid VC like the plague (personal preference), but there should be a thing at the bottom with the warnings and such and if you click on the message, it should, doesn't mean it will, but it should take you to that line in the source).
Thanks for the response and I will definately turn off the precompiled headers. To answer why I haven't dealt with "user enters 'I' or 'F'. If I type in 'r' at one year, I get $2400." is that I wanted to get the program to work using one set of the informationa and then go back and re work it for the others. I figuared I would have a base line just messing with "F" and ">=3"

I am still trying to see what nano was refering too as well, so trust me trying to work thru it
closed account (D80DSL3A)
The variables Member_Type and Years that you have declared within the Get_Dues() are not the same as the ones declared in main(). You must pass the variables into the function from main().

double Get_Dues(char MT, int Yr);

Please consider further study of the language basics before trying to write such programs. Your function returns an integer variable even though you declared it should return a double. So many errors. Slow down and study how to do it first.

EDIT: Seriously, programming is a hardcore technical subject. Taking the time to study the subject carefully is the BEST way. This will save you a lot of time and energy.
Last edited on
Please understand that I am trying to understand, I know there are errors that's why I am here. I am confused about passing the varibles from main into my Get_Dues ()function. What is wrong here? I have changed Get_Dues to an int, ensured that the names match in main, checked to make sure that char and int are specified in the function, but it won't compile. the error in the error list says

Error 1 error LNK2019: unresolved external symbol "int __cdecl Get_Dues(void)" (?Get_Dues@@YAHXZ) referenced in function _main




<stdafx.h>
<include "iomanip>
<include "iostream>

using namespace std;

char Get_Member_Type ();
int Get_Years ();
int Get_Dues ();
//void Display_Member_Info ();

int main()
{
char Member_Type;
int Years;
int Dues;

// Obtain Data

Member_Type = Get_Member_Type();
Years = Get_Years ();
Dues = Get_Dues ();

// Display Membership Type, Number of Years, and Dues

cout << endl;
cout << " Membership Type: " << Member_Type << endl;
cout << " Membership Years: " << Years << endl;
cout << " Your Dues are: $" << Dues << endl;

cout << endl;
system ("Pause");
return 0;
// End of Main

}
char Get_Member_Type ()
{
char Member_Type;
cout << " Enter your membership type followed by return. 'I' for Individual and 'F' for Family ";
cout << endl;
cin >> Member_Type;
return Member_Type;
}
int Get_Years ()
{
int Years;
cout << " Enter the number of years you have been a member " << endl;
cin >> Years;
return Years;
}
int Get_Dues (char Member_Type, int Years)
{
int Dues;

if ((Member_Type == 'F') && (Years >= 3))
{
Dues = 2400;
}
else Dues = 0;
return Dues;
}
closed account (D80DSL3A)
Wow That was fast! You must pass the variables TO THE FUNCTION when calling it.
Instead of: Dues = Get_Dues ();
Try: Dues = Get_Dues (Member_Type, Years); in main().

Other than that, what is this?
1
2
3
<stdafx.h>
<include "iomanip>
<include "iostream>


should be:
1
2
3
#include <stdafx.h>
#include <iomanip>
#include <iostream> 


EDIT: Sorry, that won't be enough to fix it. Your function prototype doesn't match the definition.
STUDY HOW TO USE FUNCTIONS.
Last edited on
Topic archived. No new replies allowed.