954,506 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Compiling problem

Ok i apologize in advance for my ignorance but i have just started learning c++ and my first program went off without a hitch now this one that im doing completely on my own is giving me some hiccups. The best i can tell is that im just having some problems compiling it through xcode or its something that i am not experienced enough yet to diagnose any help would be greatly appreciated.

#include <iostream>
#include <fstream>
#include <cstdlib>

using namespace std;

int main()
{
 const int LIMIT = 10000;
 int number = 2;
 while (number <= LIMIT) {
   int sumofDivisor = 0;
   int posDivisor = 1; 
   while (posDivisor <= number / 2)
     if (number % posDivisor == 0)
	   sumofDivisor = sumofDivisor + posDivisor;
	   if (number == sumofDivisor)
	     cout << number << "is perfect. \n";
	posDivisor ++;
	}
 number ++;
}
slayman89
Newbie Poster
12 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

Well the first thing I see is you don't have your int main() function closed, try adding a } to the end of all that.

Cameron

cbattagler
Light Poster
34 posts since Jan 2008
Reputation Points: 10
Solved Threads: 5
 

Your program as posted compiles without error for me. using VC++ 2008 Express. Looks like a logic error though -- you need more brackets around that last while loop (lines 14-18).

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

The brackets are fine. Add "return 0;" at the end of the main.

Nemoticchigga
Junior Poster in Training
98 posts since Feb 2008
Reputation Points: 10
Solved Threads: 2
 

ok so that fixed the problem of nothing being printed but i'm having trouble that it wont increase now it just says 2 is perfect then 2 is perfect

slayman89
Newbie Poster
12 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 
The brackets are fine. .


Apparently you didn't bother to read/understand the program. There are not enough brackets { and }.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

First you have too many loops. You don't need that outer loop that starts on line 11. So delete lines 11 and 20.

line 14: replace [icode]number/2[/b] with [b] LIMIT.

put open bracket at line 15 and close at line 20.

Align the program indentions correctly so that you can see what's going on.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You