Total newbie, I need more help... If you could just give me a basic structure for what I'm trying to do and an explanation, that would help a whole lot.

Here's my assignment:


1) Write a function divides. The function accepts two parameters: a number and a possible divisor. If the number is evenly divisible by the possible divisor, then the function returns 1 (or TRUE); otherwise the function returns 0 (or FALSE).

2) Write a main function that will print all the numbers between 10 and 50. Next to each number, the program will print the divisors of that number (hint: check all possibly divisors between 1 and the number).

After the entire table is printed, print the number of numbers with only 2 divisors (these are prime numbers).


I'm having trouble getting it all organized in my head in the first place... Any assistance/tips/hints would be very nice, thank you

Add the functionality in the order that it's listed in the instructions.

Make the function. Test the function in main a number or two that you know.

Test the function on one number. Figure out how many factors it has.

Repeat for all of the other numbers.

Diagram out your plan of attack on paper first...then post what code you have so far, and someone can help you from there.

question 2
////////////

void printing()
{
    cout<<setw(3)<<"numbers between 10 and 50  "<<setw(17)<<"their divisors"<<setw(18)<<"Prime Numbers"<<"\n\n";
    int i;

    for( i=11;i<50;i++)
    {
        cout<<i<<"\n";//prints all numbers between 1 and 50

        for(int j=1;j<i;j++)/*since all are divisible by 1 (between 1 and number)*/
        {
            if(i%j==0)
                cout<<"                                    "<<j<<"\n";//prints divisors of every number
        }





        }



    }
    cout<<"\n\n\n";

/*try to do the prime :) I think the ideas is clearer now and number 1 is  easier  you should be able to do it*/

}


int main()
{
printing();//function call
}

Thank you so much that's the most substantial looking answer I've gotten since I've asked for help online. I didn't even try it out yet but I just want to tell you that I am GRATEFUL as that is EXACTLY the kind of ANSWER I'm looking for people for future reference...

MY PROF ISN'T TEACHING US SHIT. I don't know what the fuck to make out of any of this. Cool, I get what you did up there, but I don't know what to FUCKING DO WITH IT. After like two hours of messing around, here's what I've got, and there are a million fucking errors, but every time I try to fix one, either 8 more come up, or they're all gone and it runs -- but the output doesn't change.

#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

void check ();
int divides (int j);

int main() {
	int i = 10;
	int divides (int value);
	
	cout.setf(ios::fixed,ios::floatfield);
	cout << setw(6) << "NUMBER" << "\t" << setw(8) << "DIVISORS" << endl << endl;
	
	cout.setf(ios::left);
	
	while (i<=50) {
		cout << setw(6) << i << "\t" << setw(4) << check(i) << endl;
		i++ ;
	}
	
	return 0;
}

void check (true, false) {
	int divides;
	if (divides=1)
		return true
		cout << divides << " " ;
}

int divides (int value) {
	int j=1;
	while (j<=value) {
		if (value%j==0) return 1;
		else return 0;
		j++ ;
	}
}

This outputs two columns: The NUMBER and DIVISORS columns, obviously. In the NUMBER column I've got a list of integers 10-50, vertically, correct. In the DIVISORS column all I have is a fucking line of ones -- as in, one column of ones. Like one 1 next to every integer in the number column. I DON'T KNOW WHAT TO DO WHAT DO I DO HOW DO I MAKE IT LIST ALL OF THE DIVISORS *NEXT TO* EACH NUMBER.

I am GRATEFUL as that is EXACTLY the kind of ANSWER I'm looking for people for future reference...

That goes against the policies of the board that "We only give homework help to those who show effort." So that's not the answer that you're going to get.

MY PROF ISN'T TEACHING US SHInola. I don't know what the fudge to make out of any of this. Cool, I get what you did up there, but I don't know what to Fudging DO WITH IT. After like two hours of messing around, here's what I've got, and there are a million fudging errors, but every time I try to fix one, either 8 more come up, or they're all gone and it runs -- but the output doesn't change.

This is just one assignment, take it one step at a time. A kabillion people have gone to college in the history of time and have had professors like yours and we're all still here to talk about it.

Do what I was telling you to do before. Write one piece of it at a time, compiling it as you go.

Your functions:

void check (true, false) {
	int divides;
	if (divides=1)
		return true
		cout << divides << " " ;
}

int divides (int value) {
	int j=1;
	while (j<=value) {
		if (value%j==0) return 1;
		else return 0;
		j++ ;
	}
}

are incorrect.

Write a function divides. The function accepts two parameters: a number and a possible divisor

Right off the bat, your function "divides" only has 1 parameter. The role of the function divides(a,b) is to see if b divides into a evenly. That's all it does. Forget about check(), it's definitely not correct. If you want to have your other function return true or false (a bool value), then it looks like that's okay by the instructions.
So,

if (value%j==0) return 1;
		else return 0;

is all that you need in the body of that function (assuming j is the second parameter)

This outputs two columns: The NUMBER and DIVISORS columns, obviously. In the NUMBER column I've got a list of integers 10-50, vertically, correct. In the DIVISORS column all I have is a frenching line of ones -- as in, one column of ones. Like one 1 next to every integer in the number column. I DON'T KNOW WHAT TO DO WHAT DO I DO HOW DO I MAKE IT LIST ALL OF THE DIVISORS *NEXT TO* EACH NUMBER.

To make a list of numbers next to another number, use a cout statement with no endl after it. Save your formatting until last, anyway.

Run this tiny program:

for(int i = 0;i<10;i++)
{
   cout<<i<<" ";  
}
cout<<endl;

For the rest of the assignment, use your function in an if statement to see if the current number (starting with the 10) divides by 1,2,3,4,5,...,10. If the number divides evenly, print it out.

You're calling for the divide function in main and check as if you are declaring a variable.

When call for a function say "void something()" in main

void something(); // void does not return anything other than run code or cout ur stuff
int somethingelse(int,int); //int function needs to return something

int main()
{
int x,y;
//You cannot call function by say "int somethingelse(x,y)" 

//you call function by their name "somethingeslse(x,y)" x and y have to be variables from main
something(); //prints out anything you cout from your function
cout<<somethingelse(23,2); //prints out the result because it returns the "result"

return 0;
}

void something()
{
int z; 

//code here
//if you call your function "somethingelse" then its:
z=somethingelse(10,2); //this is because your "somethingelse" function returns an int
//or
cout<<somethingelse(10,2); //this couts the "result" of somethingelse function

}
int somethingelse(int x, int y)
{
int result;
//code here
return result;
}

I think this what u want for question 1 but u should have tried harder these are simple questions that u should be able to answer
//////////////////////////////////////////

bool divides(int   number , int  divisor)
{
	
	if(number%divisor==0)
		return true;
	else 
		return false;
}
int main()
{
int number,
		divisor;
    cout<<"Enter the number \n\n";
	cin>>number;
	cout<<"\n\nEnter the divisor for checking\n\n ";
	cin>>divisor;
	if(divides(number,divisor))
		cout<<"yes , the number "<<number<< " is divisible by "<<divisor<<"\n\n";
	else
		cout<<"NO , the number "<<number<< " is not divisible by "<<divisor<<"\n\n";
	

}

would you please mark the thread as solved if you think you've got the help you need :)?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.