Why this code doesn’t work? It should write vertical an int | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why this code doesn’t work? It should write vertical an int

This is the code: #include <iostream> using namespace std; void write_vertical(int n){ if(n<10){ cout<<n<<endl; } else{ return write_vertical(n/10); cout<<n%10<<endl; } } int main() { int n; cin>>n; cout << "start" << endl; stampa_verticale(n); cout << "end" << endl; } There is the code, where there is the recursive function write_vertical. It should get a integer number from the input and print the number in vertical form; for example 123 should be printed 1 2 3.

30th Nov 2018, 1:07 PM
riccardo
2 Answers
+ 5
Probably because in main you are calling a function named stampa_verticale and not write_vertical.
30th Nov 2018, 1:13 PM
Anya
Anya - avatar