Click here to Skip to main content
15,889,403 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C++
#include<stdio.h>
#include<conio.h>
#include <bits stdc++.h="">
int main()
{
    int n1, n2, i, j, sum, temp;
    printf("Enter the value of n1 (starting point): ");
    scanf("%d", &n1);
    printf("Enter the value of n2 (ending point): ");
    scanf("%d", &n2);
    printf("\nPerfect numbers between %d to %d are:\n", n1, n2);
    for(i=n1; i<=n2; i++)
    {
        temp = i;
        sum = 0;
        for(j=1; j<i; j++)
="" {
="" if(i%j="=0)
" sum="sum" +="" j;
="" }
="" if(temp="=sum)
" printf("%d\n",="" sum);
="" getch();
="" return="" 0;="" 

="" int="" getsum(int="" n)
{
="" for="" (int="" i="1;" i<="sqrt(n);" i++)
="" if="" (n%i="=0)
" (n="" i)
="" i;
="" else="" 
="" i);
="" -="" n;
="" sum;
}
bool="" checkdeficient(int="" (getsum(n)="" <="" n);
}
int="" main()
{
int="" n,ctr="0;
" cout="" <<="" "\n\n="" the="" deficient="" numbers="" between="" 1="" to="" 1000="" are:="" \n";
="" "="" ------------------------------------------------\n";
for(int="" j="1;j<=1000;j++)
{
" n="j;
" checkdeficient(n)?="" n<<"="" ":="" "";
="" if(checkdeficient(n))
="" {ctr++;}
}
="" endl<<"the="" total="" number="" of="" "<<ctr="" endl;}


What I have tried:

I haven't tried anything yet since im new to c++
Posted
Updated 3-Sep-20 23:03pm
v2
Comments
CHill60 4-Sep-20 3:59am    
What is wrong with the code?
Xenon Envy 4-Sep-20 4:05am    
It won't run. There's an error with line 32 and 66 and I don't know how to fix it
Richard MacCutchan 4-Sep-20 4:36am    
The code is a mess, please use the Improve question link above and correct all the extra characters that have been added.
KarstenK 4-Sep-20 7:55am    
your code is messed up with ="" and other tokens.

First of all, most of the code is C, not C++. This is not a problem in itself, but the parts that are C++ are the out functions using cout, which is a C++ class. The compiler won't recognize it, because you did not add the headers that declare this class.

Try adding this to the start of your code:
C++
#include <iostream>
using namespace std;

This will tell the compiler about cout.

That said, as Richard said in a comment, your code is a total mess! If you want anyone to help you find the actual problem(s), if there are other ones that aren't fixed by the addition I suggested above, then please do put in at least the effort to enter the exact code that you're seeing, not some garbage you probably created by copy-pasting from some HTML source!
 
Share this answer
 
Quote:
It won't run.

This is probably the most useless problem report we get - and we get it a lot. It tells us nothing about what is happening, or when it happens.
So tell us what it is doing that you didn't expect, or not doing that you did.
Tell us what you did to get it to happen.
Tell us any error messages.

Start by making it more readable: pick an indentation style and fix your indentation to match that.
You'll start to spot compilation problems right away.
Such as : "where is the closing bracket for the main function?"
"What is this supposed to mean?":
C++
if (n%i=0)
   (n i)
i;
else 
i);
And so on.
Fix your indentation, sort out your curly brackets, try to compile again.
Then start looking at the error messages you get - they include the line number the error is on, so look closely at that and the surrounding lines to see if you can spot anythgin obvious.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900