``````#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int divides(int,int);
int main ()
{
int count = 10;
//int prime = divides(count);
int p = 0; // number of primes

cout.setf(ios::fixed,ios::floatfield);
cout << setw(6) << "NUMBER" << "\t" << setw(8) << "DIVISORS" << endl << endl;

while (count<=50)
{
//int prime = divides(count); // will return 1 or 0
int sor = 0;
int d = 0; // number of divisors
cout.setf(ios::left);
cout << setw(2) << " " << setw(2) << count << "\t" ;

for (int i=1; i<=count; i++) // i = possible divisor
{
int remainder = 0;
remainder = count%i;
if (remainder==0) {
cout << i << "\t";
d++;
}
}

for (sor<=count){
divides (count, sor)

cout << endl;

//prime = prime+prime; // count divisors
if (d==2) // if there are only two divisors -- number is prime:
p++; // count prime numbers in count

count++;
}

cout << "\n The number of the numbers with only 2 divisors is " << p << "." << endl;

return 0;
}

int divides (int n, int div) {

if (n%div==0)
return 1;
return 0;

}``````

I hope you see what I'm trying to do. I got the program to work exactly like it had to but I can't figure out how to implement the divides function within the main function, which I need to do. I'm not supposed to do that part of the counting primes within the main function... or whatever it does I don't know how to get it to work inside, like how do I call it and get it to ultimately count up all the primes?! You see like draft attempts I was working on and now I'm trying to add in this function call and you'll see where... but leaving the program as it is how it works, but I need to make the function call work so I can take that out. Please help me and tell me what to do or give me someplace to start or explain it to me. Thank you so much.

3
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by caltech

Your divides function takes two int objects as parameters, and returns an int.

Accordingly, you must call it like this:

``returnedInt = divides (someInt, someOtherInt);``

where returnedInt, someInt and someOtherInt are all of type int.

Edited by Moschops: n/a

Your divides function takes two int objects as parameters, and returns an int.

Accordingly, you must call it like this:

``returnedInt = divides (someInt, someOtherInt);``

where returnedInt, someInt and someOtherInt are all of type int.

Or, he could use an if statement to check the returned value like so:

``if(!divides(input1,input2)``

Which would return true if the function = 0 (false).

That just doesn't help enough somehow I need to call that divides function so that it ultimately helps me produce what "p" is now. You see?

Oh, I see; you just don't understand how to use the divides function to evaluate if a number is a prime number or not?

Take the number n you want to test, and pass it to the divides function repeatedly, with every possible value of div that is less than n and greater than 1. If any of the calls to divides return 1, the number is not prime.

Edited by Moschops: n/a

Haa figured it out in class