c++ code writing

I have this program but don't know what to add so that it runs. I want to put f=10015. I tried to add #include<iostream> but not working.

void f(int n,int m){
cout<<f;
if (m>n) return;
if(n%m==0)
f(n,++m);}
Hello paula12,

PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.

What you have is a function not a program. "iostream" is need to use the "std::cout" and "std::cin" statements. A quickprogram to show you how this will work:

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
#include <iostream>

void f(int n, int m)
{
	std::cout << f;
	if (m>n) return;
	if (n%m == 0)
		f(n, ++m);
}

int main()
{
	int n{ 0 }, m{ 0 };

	std::cout << "\n Enter a number: ";
	std::cin >> n;

	std::cout << "\n Enter a number: ";
	std::cin >> m;

	std::cout << std::endl;

	f(n, m);

	std::cin.ignore(10000, '\n');
	std::cin.ignore();

	return 0;
}


Without the main function it will not work unless the function is part of a whole.

Hope that helps,

Andy
Thank You Andy. I will remember it
Topic archived. No new replies allowed.