+ 1

Code problems

#include <iostream> #include <vector> static void takeChar(int ch); class Number{ public: void setNum(){ std::cin >> num; } int getNum(){ return num; } private: int num; }; int divide(){ Number *n = new Number; n->setNum(); int number = n->getNum(); int cNum = number; while(number > 0){ number%=10; takeChar(number); number = cNum/10; cNum = number; } return number; } int main() { divide(); return 0; } void takeChar(int ch){ static std::vector<int> chars; chars.push_back(ch); if(divide() < 0){ for(auto v : chars) std::cout << v; } } Memory problem or something.

22nd Aug 2018, 4:32 PM
Oleg Storm
Oleg Storm - avatar
3 Respostas
+ 1
Oleg Storm in your code, I don't understand benifit of recursive call in takeChar function... can't you make it very simple as below single line in it? cout << v << endl; I guess what you have done is calling Divide again from takeChar results into recursive call
22nd Aug 2018, 7:26 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 1
Ketan, that's it, thanks for help🤗
22nd Aug 2018, 8:40 PM
Oleg Storm
Oleg Storm - avatar
0
Happy to help
23rd Aug 2018, 1:41 AM
Ketan Lalcheta
Ketan Lalcheta - avatar