function void main()

Jun 23, 2017 at 2:45am
#include<iostream>
using namespace std;
int i;
void main()

{
i=10;
cout<<"\n"<<"in main(), the value of i is:"<<i;
f();
cout<<"\n"<<" back in main(),the value of i is:"<<i;
}
void f()
{
cout<<"\n"<<"in f(),the value of i is:"<<i;
i=20;

}

unable to compile this program. compiler give void main error please help
Jun 23, 2017 at 3:55am
I believe this is what you wanted..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include<iostream>
using namespace std;

void f()
{
	int i = 20;
	cout << "\n" << "in f(),the value of i is:" << i;
	

}


int main()
{
	int i = 10;
	cout << "\n" << "in main(), the value of i is:" << i;
	f();
	cout << "\n" << " back in main(),the value of i is:" << i;
	return 0;
}


Tried Leaving everything as similar to original as possible
 
void main() // <--- Change this to int main() 


Also you would need to put void f() above int main (), so main() knows what f() does


P.S. use source code in format so its easier to read your code! Thanks!
Last edited on Jun 23, 2017 at 4:42am
Jun 26, 2017 at 2:57pm
closed account (1vf9z8AR)
see what tulu wrote and instead of void main() use int main() and before the last } inside main() use return 0;
Topic archived. No new replies allowed.