can someone please tell me how functions work??

i am teaching myself c++ and i thought that when i pass an argument to a function it supposed to use it. but his one says "salary was not declared in this scope" what????

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
#include <iostream>
 
using namespace std;


void qualify(){
	cout << "congratulations you qualify!! our card comes with a 12% annual interes fee." << endl;
}
 
 void noQualify();		// function prototype
 
int main()
{
 double salary;
 int years;
 
 
 cout << "This program will determine if you qualify\n";
 cout << "for out cridit card.\n";
 cout << "what is your annual salary? ";
 cin >> salary;
 cout << "How many years have you worked at your ";
 cout << "current job? ";
 cin >> years;
 if (salary  >= 17000.0 && years >= 2)
 	qualify();
  else
  	noQualify(salary);
  return 0;
}
 
 void noQualify(){
 	if (salary < 17000.0)
 		cout << "your salary isnt enough to meet our minimum requierments." << endl;
 	else
 		cout << "you dont have the experiance in your work area to meet our minimum requierments." << endl;
 }
When you declare a variable inside a function, it remains local to that function; i.e. you can't use it anywhere else.

Inside noQualify(), you have neither a parameter called 'salary' nor a local variable with that name, thus the compile error.

I made a video on functions, hope it helps:
https://www.youtube.com/watch?v=xYsD59UdGUc

Let me know if you need more help,
Joseph (Concord Spark Tutoring)
sparkprogrammer@gmail.com
At this web site there is a great tutorial. http://www.cplusplus.com/doc/tutorial/

The page that will help you the most right now is http://www.cplusplus.com/doc/tutorial/functions/.

Topic archived. No new replies allowed.