i have written the code. why is it giving the error. please look into and only explain the corrections which i need to make no solution on ide.
Armstrong cod is giving the error
What are you trying to do?
That will help me to highlight your mistakes.
i am writing the code to find out whether the given number is armstrong or not.
Ye, but how are doing that, what is your logic?
where is my logic is wrong? please tell me with line number.
here is my code. please point out my mistake
#include
using namespace std;
bool isarmstrong(int armstong=371){
if(isarmstrong){
cout<<“true”<<endl;
}
else{
cout<<“false”<<endl;
}
}
int main(){
int armstong=371;
isarmstrong(armstong=371);
return 0;
}
Yes, but What do you think this line does
if(isarmstrong)
i am writing function using bool operator and bool operator returns only true or false value. so in this statement i am comparing the number 371 (which is written in function) if it is true then cout<<---- else cout<<----…
what is wrong in it?
No, this is not how you do this.
What is that you want to do?
Take a number and see if it is equal to 371 or not?
see this is the code which i have written in sublime text editor
and this is the solution
and it is working fine on my pc but not working good on online judge.
#include<iostream>
using namespace std;
bool isarmstrong(int armstong=371){
if(isarmstrong){
cout<<"true"<<endl;
}
else{
cout<<"false"<<endl;
}
return true;
}
int main(){
int armstong=371;
isarmstrong(armstong=371);
return 0;
}
This will work on online judge as well, but I am not sure if it will work in the same way as you want.
this is also not working on online judge. i submitted it and it shows the message that wrong answer.
Yes, because it is definitely wrong.
Here is the correct code
#include <iostream>
using namespace std;
int main() {
int num, originalNum, remainder, result = 0;
cin >> num;
originalNum = num;
while (originalNum != 0) {
// remainder contains the last digit
remainder = originalNum % 10;
result += remainder * remainder * remainder;
// removing last digit from the orignal number
originalNum /= 10;
}
if (result == num)
cout << num << " is an Armstrong number.";
else
cout << num << " is not an Armstrong number.";
return 0;
}
If this is your first time programming, then leave this problem for some time and try it after some time.

