what is wrong with this program

Can anyone please tell me what is wrong with this program ?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<iostream>
using namespace std;
void write_vertical(int n);
int main()
{
	cout<<"write_vertical(3)  "<<write_vertical(3);
	cout<<"wrtie_vertical(12)   "<<write_vertical(12);


	cout<<"wrtie_vertical(123)   "<<write_vertical(123);
return 0;
}
void write_vertical(int n)
{
	if (n<10)
	{
		cout<<n<<endl;
	}
	else
	{
		write_vertical(n/10);
		cout<<(n%10)<<endl;
	}
}
Last edited on
some typos there on the last two in main.
other then that, the code looks fine, i think you might want to switch the else though, and put the cout before the recursion.
Last edited on
take out the quotation marks, you dont need them.


Hi daeiros, could you please explain as to why he has to remove quotes?
If I am not wrong he is using that expression to show the output for the given function call.
Last edited on
removing the quotation marks didn't work.

the error is too big that i cann't even paste that here.


Last edited on
yeah i realized that... that why i edited. uhh the only error i get is the fact that in order to cout your function it needs to return something, because currently its a void type.
removing the quotation mark had nothing to do with your code.

@daeiros: Please avoid editing your post especially after someone has commented on your post. If you want to edit it, then write in your post that you have edited it.

@jayt: The problem that I see with your code is that you are writing

cout<<" -- "<<write_vertical(12);

Try this
1
2
3
cout<<"write_vertical(12)";
write_vertical(12); 
 
Thank you kevinchkin and daeiros!!
you have been a great help.

@ daeiros!!

can you please explain this program too like you did the other one.
how is 1,2,3 coming down ??
Last edited on
Topic archived. No new replies allowed.