perfect integers up to 100

This is a discussion on perfect integers up to 100 within the C++ Programming forums, part of the General Programming Boards category; well all im trying to do is get the perfect factor from 1-100 so why the hell does this crash ...

  1. #1
    Unregistered
    Guest

    perfect integers up to 100

    well all im trying to do is get the perfect factor from 1-100 so why the hell does this crash

    and what is a boolean function since i am supposed to make IsPerfect() a boolean function

    Code:
    #include <iostream.h>
    
    //-------------------------------------------------------------------
    void IsPerfect()
    {
    	int count,totalfactors,perfect=0;
    
    	for(count=0;count<=100;count++)
    	{
    		int count2;
    		totalfactors=0;
    
    		for(count2=0;count2<=count;count2++)
    		{
    			if(((count%count2)==0)&&(count!=count2))
    			{
    				totalfactors+=count2;
    			}
    		}
    		
    		if(totalfactors==(count2+1))
    		{
    			perfect++;
    		}
    	}
    	cout<<totalfactors;
    }
    //-------------------------------------------------------------------
    int main()
    {
    	IsPerfect();
    	return (0);
    }

  2. #2
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    A) Try not to declare variables inside a loop. Instead, declare them before the loop.

    B) A boolean function is a function that returns a boolean value (true or false). False is normally represented as 0, and true is normally represented as 1 (sometimes any non zero value).

  3. #3
    Unregistered
    Guest
    you have IsPerfect() declared as a void function, it should be:

    bool IsPerfect();

  4. #4
    Unregistered
    Guest
    Originally posted by golfinguy4
    A) Try not to declare variables inside a loop. Instead, declare them before the loop.

    B) A boolean function is a function that returns a boolean value (true or false). False is normally represented as 0, and true is normally represented as 1 (sometimes any non zero value).
    :| well i did that and its still crashing when running

  5. #5
    Registered User
    Join Date
    Jan 2002
    Posts
    552
    1 = 1
    1 + 3 = 4
    1 + 3 + 5 = 9
    1 + 3 + 5 + 7 = 16
    1 + 3 + 5 + 7 + 9 = 25
    1 + 3 + 5 + 7 + 9 + 11 = 36
    .
    .
    .
    1 + 3 + 5 +... + n-1 + n = nth perfect number

  6. #6
    Unregistered
    Guest
    Originally posted by *ClownPimp*
    1 = 1
    1 + 3 = 4
    1 + 3 + 5 = 9
    1 + 3 + 5 + 7 = 16
    1 + 3 + 5 + 7 + 9 = 25
    1 + 3 + 5 + 7 + 9 + 11 = 36
    .
    .
    .
    1 + 3 + 5 +... + n-1 + n = nth perfect number
    i want perfect factors from 1-100

    so 1+2+3=6

    anywyas nm all i got it to work :P

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 05:55 PM
  3. socket question
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 07-19-2002, 01:54 PM
  4. Unconvertable?
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 04-02-2002, 07:10 PM
  5. Homework help
    By Jigsaw in forum C++ Programming
    Replies: 2
    Last Post: 03-06-2002, 04:56 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21