0

We have to write a program that prompts a user to input an integer and after that i get lost i attached the problem to this thread and help would be greatly appreciated!!

Edited by ITHope: n/a

Attachments compt._.jpg 143.43 KB
4
Contributors
7
Replies
8
Views
6 Years
Discussion Span
Last Post by ITHope
0

Reading in the integer as a string would probably be the easiest. Take a crack at it and post your attempt, otherwise we will not be able to help you.

0

actually i'm not kidding and i idd the code i thought i posted it sorry it keep saying it wont build due to errors post comeing soon with code

0
#include<iostream>
#include<cmath>
using namespace std;
int main()
{int num;
int sum;
int i;
intcount=0;
cout<<"Enter a positive integer: ";
cin>>num;
while(num<=0)
    {cout<<"invalid input must be greater than 0";
     cout<<"Enter a positive integer> ";
     cin>>num;
     }
sum=0;
for(i=11;i<num;i++)
    if(num%i==0)
        {sum+=i;
        count++;
        }
if(sum==num)
     {cout<<num<<" is a perfect number.\n";
     cout<<num<<" = ";
         for(i=11;i<num;i++)
            if(num%i==0)
                 {count--;
                  cout<<i;
                  if(count>0)
                      cout<<" + ";
                      }
          cout<<endl;
          }
else
   cout<<num<<" is not a perfect number.\n";

 return 0;
}

Edited by Reverend Jim: Fixed formatting

0

Explain to me how your code solved the problem as it was given to you. It does not ask about divisibility by 11 directly, it asks you to use that method they gave you.

Also, please use code tags [code] //code goes here [/code] when posting code.

Hint: you need some way to get the digits of the number. Meta-hint: I gave you a hint on how to do that. With an integer it takes a lot more effort to get the digits.

0

@jonsca okay thanks i think i figured it out how to do that!!!!!... and sorry about the code

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.