Why is there no output for the following code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why is there no output for the following code?

#include <iostream> #include <string> #include <sstream> using namespace std; string isAutomorphic(){ string a; int num; int is; int c; string f; string r; string x; stringstream stream; cin >> a; stream << a; stream >> num; int b = num * num; stream.str(""); stream << b; stream >> x; int z = num; is = x.find_last_of(z); stream.str(""); stream << num; stream >> r; if(is == (r.size() - (r.size() - is))){ f = "Yes, it is an automorphic number."; } else{ f = "No, it is not an automorphic number."; } stream.str(""); return f; } int main() { isAutomorphic(); return 0; }

3rd Apr 2018, 1:08 AM
mei
mei - avatar
3 Answers
+ 1
Try putting this code: cout << isAutomorphic() << endl; instead of just isAutomorphic() inside the main() function.
3rd Apr 2018, 1:31 AM
Emma
+ 1
Thanks!
3rd Apr 2018, 1:35 AM
mei
mei - avatar
+ 1
Oh, I edited the code, it works, but it's stuck on "Yes, it is an automorphic number." Code: #include <iostream> #include <string> #include <sstream> using namespace std; string isAutomorphic(){ string a; int num; int is; int c; string f; string r; string x; stringstream stream; cin >> a; cout << "Your number: " << a << endl; stream << a; stream >> num; int b = num * num; cout << "Squared: " << b << endl; stream.str(""); stream << b; stream >> x; int z = num; is = x.find_last_of(z); stream.str(""); stream << num; stream >> r; if (is != (r.size() - (r.size() - is))){ f = "No, it is not an automorphic number."; } else if (is == (r.size() - (r.size() - is))){ f = "Yes, it is an automorphic number."; } stream.str(""); return f; } int main() { cout << isAutomorphic() << endl; return 0; }
3rd Apr 2018, 1:43 AM
mei
mei - avatar