function problem

Hi all,

I'm working on a midterm project, its long, but my question is about a small portion of it.

I'm listing 3 options for auto-coverage;

1) semi-annual costing $3500
2) cover by collateralizing bod worth of $500,000 (which will list as cost $0)
3) Use the $500,000 to buy into a mutual fund with a return of 6% (will list as 6% of $500,000 of cost deduction towards annual expenses.

the coverage will be calculated based on which of these the user selects, but whatever I input for selection, the selection seems to always=0, I think my problem is with the function input(selection), but I dont see anything wrong with my function...Any help will be highly appreciated...thanks in advance...



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include<iostream>
#include<cmath>
#include<string>
#include<iomanip>
using namespace std;

#define m4 ("Your selection does not apply to one of the listed options.")

void input(int); 

int main()
{	
double semiannual_ins=3500;
double const bond(500000);
double mutualfundinterest=0.06;
double coverage;
int selection;

        while(cin)
		{
			input(selection);
			if (selection==1)
			{
				coverage=semiannual_ins*2;
				break;
			}
			else if (selection==2)
			{
				coverage=0*bond;
				break;
			}
			else if (selection==3)
			{
				coverage=mutualfundinterest*bond;
				break;
			}
			else
			{
				cout<<m4;
				cin>>selection;	
			}
		}
void input(int selection)	//function for userinput.
{
	cout<<m3;
	cin>>selection;
}
input() takes an int, so it's unable to modify its actual parameter. It can only modify its formal parameter.
Either make input() take a reference, or make it return the value of the variable you stored the user's input in.
Thanks for your response helios. This is my first course in c++ and im not sure I understand what you mean by actual and formal parameters, reference for the input(), or how would I go about returning the value of the variable... if you find the time to further explain that to me, I'd appreciate it.
change the function void input(int selection) to void input(int & selection)
Topic archived. No new replies allowed.