+ 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; }
3 Answers
+ 1
Try putting this code:
cout << isAutomorphic() << endl;
instead of just isAutomorphic()
inside the main() function.
+ 1
Thanks!
+ 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;
}