separating a three digit number using reference

So heres what I have to do
Write a function called breakThree that will accept a 3 digit integer and returns each of the numbers individually. This function will take four paramaters. The first parameter is the three digit number to break apart. Parameters 2 through 4 are passed by reference and will be used to return each of the numbers back to main.
You should make sure that the input into the function is a 3-digit number. If it is not a three digit number the breakThree function should simply return false. If it is a three digit number the breakThree function should break the number apart, and store each of the numbers in the parameters passed by reference.
In main you should get the number from input and then output each of the numbers on a separate line.

What not to use
global variables
cin in breakThree function
cout in breakThree function
goto statements



yes this is homework no i don't want you to do it for me. heres what I have so far please help the tutors at my school are unavailable on fridays and the assignment is due sunday
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//
//  main.cpp
//  assignment 13
//

#include <iostream>
using namespace std;

void separate(int a, int b, int c, int d);
int main(int argc, const char * argv[])
{
    int num;
    int a;
    int b;
    int c;
    cout << "enter a three digit number" << endl;

    cin >> num;
    separate(a,b,c);
    
    

    
    
    return 0;
}

void separate(int &a, int &b, int &c, int &d)
{
    d = a % 10;
    c = (a / 10) % 10;
    b = a / 100;
    
    return;
}
Last edited on
So what is your question?

Some obvious problems:
1) Your function prototype and your function do not match.
2) When you call separate, you pass only 3 arguments, not 4.
3) Instructions say "output each of the numbers on a separate line". You're not doing that.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
http://v2.cplusplus.com/articles/jEywvCM9/
It makes it easier to read your code and it also makes it easier to respond to your post.
Duplicate post. I already answered this here:

http://www.cplusplus.com/forum/general/114788/

Please do not post the same thing multiple times, OP.
Looking at your other post not sure what your question is. The other users provided good instructions. Here is some unfinished code if you read over the other post you should be able to follow along.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
using namespace std;

bool separate(int,int&,int&,int&);

int main(){
	int num, a, b, c;

	cout << "enter a three digit number" << endl;

	cin >> num;
	
        //Finish Up
        separate(num, a, b, c);
	
	

	return 0;
}

bool separate(int num, int &a, int &b, int &c){

	//Your Function Here

}
ok so heres what I have and I am having trouble figuring out how to do the function
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
using namespace std;

void separate(int a, int b, int c, int d);
int main(int argc, const char * argv[])
{
    int num, a, b, c;
    cout << "enter a three digit number" << endl;
    cin >> num;
    separate(int num, int a, int b, int c)
    
    
    return 0;
}

bool separate(int num, int &a, int &b, int &c)
{
    num = a % 10;
    c = (a / 10) % 10;
    b = a / 100;
    
    return num;
}
now i am here and I still need help
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//
//  main.cpp
//  assignment 13
//

#include <iostream>
using namespace std;

void separate(int a, int b, int c, int d);
bool breakThree(int num, int &a, int &b, int &c);

int main(int argc, const char * argv[])
{
    int num, a, b, c;
    cout << "enter a three digit number" << endl;
    cin >> num;
    breakThree(a, b, c)
    
    return 0;
}

bool breakThree(int num, int &a, int &b, int &c)
{
    num = a % 10;
    c = (a / 10) % 10;
    b = a / 100;
    
    return num;
}
Last edited on
I need to know what the function is and why it is telling me that there is no matching function when I have prototyped it at the top
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
using namespace std;

void breakThree(int num, int &a, int &b, int &c);

int main(int argc, const char * argv[])
{
    int num, a, b, c;
    cout << "enter a three digit number" << endl;
    cin >> num;
    breakThree(a);
    breakThree(b);
    breakThree(c);
    
    
    return 0;
}

void breakThree(int num, int &a, int &b, int &c)
{
    //function goes here
    
    return 0;
}
so here is what i have now
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//  main.cpp
//  assignment 13
//

#include <iostream>

using namespace std;

void breakThree(int &a, int &b, int &c, bool &morethanthree);

int main()
{

    int x;
    int y;
    int z;
    cout << x << endl;
    cout << y << endl;
    cout << z << end;
    
    
    return 0;
    
}

void breakThree(int &a, int &b, int &c, bool &morethanthree)
{

    int num;
    cout << "enter a three digit integer" << endl;
    cin >> num;
    a = num %10;
    b = (num/10) %10;
    c = num/100;

    
    
    

    return;
}
Please stop posting this in multiple threads.

I already answered this here:

http://www.cplusplus.com/forum/general/114788/#msg627607
Topic archived. No new replies allowed.