![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,254
Rep Power: 5
![]() |
If you want help on an error message, it's a good idea to give us the same information your compiler gave you (eg the text of the error message, the line number it highlightd as a problem).
In this case, the problem is when you're calling divisor_count. divisors = divisor_count(int x); |
|
|
|
|
|
#12 |
|
The Oblivious One
Join Date: May 2005
Location: Ontario, Canada
Posts: 646
Rep Power: 4
![]() |
You are also going to have to update the maximum number of divisors so far. In your current code, you are only updating the number with the maximum divisors.
![]()
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS! |
|
|
|
|
|
#13 |
|
Newbie
Join Date: Jan 2007
Location: Hershey, the sweetest place on earth
Posts: 19
Rep Power: 0
![]() |
Thanks Guys! Here we go:
#include <iostream.h>
int divisor_count (int n);
int main()
{
int x;
int divisors;
int max_divs = 0;
int max_num = 0;
int last_num = 1000;
for (x = 1; x <= last_num; x++)
{
divisors = divisor_count(x);
if (divisors > max_divs)
{
max_num = x;
max_divs = divisors;
}
}
cout << "The number with the most divisors is " << max_num << endl;
return 0;
}
int divisor_count (int n)
{
int count = 1;
for ( int i = 2; i <= n; i++ )
{
if ( n % i == 0 )
++count;
}
return count;
} |
|
|
|
|
|
#14 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Review post #6 regarding iostream.h. May as well get off the non-standard stuff now.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#15 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 882
Rep Power: 4
![]() |
for ( int i = 2; i <= n; i++ ) |
|
|
|
|
|
#16 | |
|
The Oblivious One
Join Date: May 2005
Location: Ontario, Canada
Posts: 646
Rep Power: 4
![]() |
Quote:
Oops. :o
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS! |
|
|
|
|
|
|
#17 | ||
|
Programming Guru
![]() Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 6
![]() |
Quote:
Quote:
__________________
i put on my robe and wizard hat... Have you ever heard of Plato, Aristotle, Socrates?...Morons. |
||
|
|
|
|
|
#18 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 882
Rep Power: 4
![]() |
Whats does that mean bl00dninja? If you look at the code Jessehk was referring to, it is trying to find the number with the most divisors by checking the number of divisors of this number with the maximum number found so far (max_divs). Jessehk was pointing out that the code did not update the max_divs variable value inside the loop, so it would not work (it would always return 1000).
|
|
|
|
|
|
#19 |
|
Programming Guru
![]() Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 6
![]() |
ahhhhhhhhhhhhhhh...
my bad. ![]()
__________________
i put on my robe and wizard hat... Have you ever heard of Plato, Aristotle, Socrates?...Morons. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Finding Random Min and Max | imagikricei | C++ | 18 | Jun 12th, 2006 1:29 PM |
| Sum of Divisors | titaniumdecoy | Software Design and Algorithms | 20 | May 14th, 2006 4:24 PM |
| Finding Patterns | jobobshishkabob | C++ | 24 | Feb 26th, 2006 3:49 AM |
| finding the number of spaces in a String | squishiful | Java | 6 | Jul 6th, 2005 6:43 PM |
| Help with finding windows programming books | some1 | C++ | 11 | Feb 9th, 2005 10:19 AM |