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!!

Recommended Answers

All 7 Replies

Your kidding right? What is this this? Spam?

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.

You must be kidding...some sort of crap is this!

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

#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;
}

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.