Can you use two data types in a function

I was wondering can you use two data types in a string like

int char function( int 5 , char b)

Or do i need to use a function string?
It is interesting and what are you going to return from the function?!
you can do
char myfunc(int &i, char c){
//do whatever you want
return c;
}

the reference & transfers the actual variable and not just the value within the variable, so any changes you make to i will also happen to you variable you plug in for example

char myfunc(int & i, char c){//declare the actual execution below main
i++;
return c++;
}

int main(){

int i = 0;
char c = 'a';

myfunc(i,c);
std::cout << i << " "<< c; // the output is 1 b
}
cin.ignore(); // no system functions
return 0;
}
Last edited on
i kind of get you ui uiho

Im trying to get user input in this format : 3/5 + 1/5
and output it like this

solution : 4/5

[code]char userInt(int& num1, char /, int&denum1, char mid, int& num2, char 2/ ,int&denum2)

///
num1= numerator
/ = the "/" between 3 and 5
denum1= denominator.

//
mid = " " it could be +,-,*,/[/code]
you get the idea for the rest it's the same of the seond fraction.


correct me if im wrong
Last edited on
that seems to work, you can put in
if( denum1 == denum2) num_answer = num1 + num2;

and similar statements to allow your program to be more efficient, you need to know about division of integers, and to include num1/(num2 * 1.0) in order to get a float. if you want it to stay in fraction form it is required to convert the values of each fraction to the required denominators are the same, easiest way to do this is

num1 *= denum2;
num2 *= denum1;
int hold = denum1;
denum1 *= denum2;
denum2 += hold;
int sumnum = num1+num2;
int sumdenum = denum1+denum2;
if( sumnum % 2 == 0 && sumdenum % 2 == 0) {
sumnum /= 2;
sumdenum /= 2;
} // do this for numbers 2, 3, 5, 7.

that is the easiest way for fraction reduction, there also might be a function in the library math.h but i did not memorize that complete library.

Topic archived. No new replies allowed.