Variable Won't Run

I am having problems with getting my program to work, I know that int num is not getting into the various three digits I have set up in my function.

#include<iostream>
using namespace std;

void BreakUp (int &uno, int &dos, int &tres, int num){
//Break Up The Number
uno=num/100;
dos=(num%10)/10;
tres=num/10;
}
int Build (int un, int du, int twa){
//Return Value with the digits from Number
int build;
build=((un*100) + (du*10) + (twa));
return(build);
}
int main(){
int num, one, two, three, build;
one=0;
two=0;
three=0;

cout<<"enter a number ";
cin>>num;
build=num;
BreakUp(one, two, three, num);

if (num!=Build(one, two, three))
cout<<"ERROR: original and rebuilt numbers do not match"<<endl;
return(0);
}
Last edited on
As it says you have not set the variable to equal anything


Please always use code tags - the <> button on the right
I set my variables equal to 0 but that simply gives me zeros each time i run it. I am not sure how to fix my program from here.
Your breakup function does not return a value, but it seems that you intend to use the values that you send it in another part of the program.

try passing the three as a reference:

1
2
3
4
5
6
void BreakUp (int& uno, int& dos, int& tres, int num){
//Break Up The Number 
uno=num/100;
dos=(num%10)/10;
tres=num/10;
}
Last edited on
how would I go about transferring the values of uno dos and tres to int Build where i have un du twa?
exactly how i explained it. When you pass by reference you are passing the actual memory location. When you pass by value it works with the value, and not the memory location.

read here:
http://www.cplusplus.com/doc/tutorial/functions2/

Sorry, i said num, but i meant uno, dos, tres.
Thank you that helped I was able to solve it along with adjusting my math and removing some unnecessary code.
Topic archived. No new replies allowed.