Functions Help

How do i get this 'fun' function to run properly in the main function. Also, any advice on functions in general would be helpful.

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 fun(int n) {
	cout << "Guess the number between 1-10" << endl;
	int n;


	do {

		cin >> n;

		if (n != 5) {
			cout << "Incorrect, please try again." << endl;

		}
		if (n == 5) {
			cout << "Nice Job" << endl;
			break;
		}
	} while (n != 5);

}



int main() {

	fun();

}

Last edited on
Your function must have a parameter. Either pass it a parameter in main or rewrite it so it doesn't take a parameter.
I know it needs a parameter but I don't know how to do it.
Here is how to call a function that takes a parameter. In this example, the function is called "function" and the parameter is called "parameter_one".

fun(parameter_one);
Line 8: Why are you even passing n as an argument? The int n at line 10 hides the argument n, thereby making it useless.
Topic archived. No new replies allowed.