Hi, so I'm taking computer programming in school and one of the assignments we have is really stumping me.
We have to put a fraction in decimal form and mixed number form (letting the user input the numerator and denominator) WITHOUT using floats or doubles. Besides those data types, we've only learned about ceil, floor, fabs, pow, etc. but I doubt my teacher wanted that but anything is welcome.
Btw, this is the second language I'm learning, the first one being QBasic.
Thank you! :)
cout << "Input the numerator" << endl;
cin >> num1;
cout << "Input the denominator" << endl;
cin >> deno
cout << "The fraction is " << num1 << "/" << deno << endl;
cout << "The mixed number is " << (After this I don't know how to format it like this eg. 7/2 = 3 1/2)
[this is roughly my code, i don't have my exact one bc I can only run C++ at school]
It will return the remainder of a division operation for you.
Plain integer division: 7/2 = 3
Modulus: 7/2 = 1 ( It just gives you the remainder, that's all)
So you can get the whole number with plain integer division, then the numerator for the fraction using modulus. If you wanted to simplify the fraction part of the mixed number, well that'd be extra work and I don't know if you need to do that or not. If you did simplify it though, modulus would continue to prove itself useful ;)