# need help with fractions in C++

Show 80 post(s) from this thread on one page
Page 3 of 3 First 123
• 02-19-2012
rogster001
far too many uninitialised variables, set things to 0 as often as you can, at least then you have a known value to work with. and at least as a basic protection against bad user input in this case., this thread is littered with examples of you just not taking any notice of good advice given.

and ay caramba :

Code:

```int simplify(int x2 ,int y2 ,int gcd ,int a ,int b ) {         a= x2/gcd;     b= y2/gcd;     return simplify; }```
What on earth do you think simplify will be?
• 02-19-2012
Agnes Roguska
Code:

```#include "stdafx.h" #include <iostream> using namespace std;     int simplify(int x2 ,int y2 ,int gcd ,int a ,int b ) {         a= x2/gcd;     b= y2/gcd;     return simplify( x2, y2, gcd, a,b); }      int gcd(int x2, int y2) {     int i;     int gcd2;     for (i=1; i<=x2; i++)     {         if((x2%i==0) && (y2%i==0))             gcd2 = i;     }     return gcd2;    } int multiply() {     int numerator,denominator,numerator2,denominator2 ;     int x;         int x2, t2;         int c;         int d;     cout<<"Input the numerator and denominator of a fraction separated by spaces :"<<endl;     cin>>numerator;     cin>>denominator;       cout<<"Input the numerator and denominator of a fraction separated by spaces :"<<endl;     cin>>numerator2;     cin>>denominator2;       cout<<"Input instruction*_" << endl;     x2 = numerator*numerator2;     t2 =denominator*denominator2;         x=gcd( x2, t2);     simplify(  x2 ,  t2 ,x , c ,  d);           cout<<"("<< numerator << "/"<<denominator <<") * ("<< numerator2 <<"/"<< denominator2 <<") = " << c << "/" << d;     cout << "\n";     return 0; }       int main()          {     multiply();     system ("PAUSE"); }```
• 02-19-2012
rogster001
right erm, yea.

If you want good help, its a two way thing, are you really so unbelievably lazy and rude that you think its ok to just dump wedges of code by way of a response every time? And then expect to get expert help from the board members, when its a bloomin sunday too.

Why not add some words too?????
• 02-19-2012
Elysia
At this point, you are just guessing.
Work with us - what is it that you fail to understand?
• 02-19-2012
Agnes Roguska
rogster Im not rude... I sitting on this project and really have enough . im dont want to be a programmer its only one of my subjects which i need to pass.. I dont even like it. u think for me its easy to ask like an idiot 10 times this same.. ..
i will be never a programmer..
i really need help to finish it..
• 02-19-2012
laserlight
Well, even more than you not wanting to be a programmer, we don't want to be robots :)

So, when you post your code, tell us: what's wrong?
• 02-19-2012
Elysia
Regardless, the subject is there for a reason. Therefore, you need to make sure you acquire the abilities needed to pass the course. It doesn't matter whether you like it or not.
Tell us what you are having problems with - in details, or just forget about getting any help. We cannot help you if you do not work with us, and we will not do your homework for you.
• 02-19-2012
Agnes Roguska
why return simplify( x2, y2, gcd, a,b);
didnt return the values to multiply
• 02-19-2012
Elysia
What do you expect it to do? That's a function call.
• 02-19-2012
rogster001
well its a bit of a shaky one, but an oft quoted:

"To ask may be but a moment's shame, not to ask and remain ignorant is a lifelong shame"

We don't mind how often you ask questions, that is good, and it is true that by teaching you learn, so like i say it is a two way thing, I would not bother answering at all otherwise.

You just have to consider how it looks when code is posted without any other message, It comes across very badly, no one is paid here remember.
Fair enough you dont like programming, but as Elysia points out it is a pre requisite of your course, I hated half the crap i had to learn too,( my study was nothing to do with IT or technical by the way) but it is a case of shifting your mindset and concentrating on the long term goal.
• 02-19-2012
Elysia
To be honest, the problem you are facing is that you are not reading.
You want to return two values from a function. We say: "use references." I even gave you an example in post #18: http://cboard.cprogramming.com/cplus...ml#post1090046
But nowhere in your code do I see you using references.
• 02-19-2012
Agnes Roguska
Code:

```#include "stdafx.h" #include <iostream> using namespace std;   int simplify(int x2 ,int y2 ,int gcd ,int a ,int b ) {         a= x2/gcd;(simplify its counting a and b)     b= y2/gcd;     return (x2,y2,gcd,a,b); now its returning the x2,y2,gcd,a,b but the value of and b its different }      int gcd(int x2, int y2) {     int i;     int gcd2;     for (i=1; i<=x2; i++)     {         if((x2%i==0) && (y2%i==0))             gcd2 = i;     }     return gcd2;    } int multiply() {     int numerator,denominator,numerator2,denominator2 ;     int x;     int x2, t2;     int c;     int d;     cout<<"Input the numerator and denominator of a fraction separated by spaces :"<<endl;     cin>>numerator;     cin>>denominator;       cout<<"Input the numerator and denominator of a fraction separated by spaces :"<<endl;     cin>>numerator2;     cin>>denominator2;       cout<<"Input instruction*_" << endl;     x2 = numerator*numerator2;     t2 =denominator*denominator2;         x=gcd( x2, t2);     simplify(  x2 ,  t2 ,x , c ,  d); here im sending arguments  to simplify(1)                3)its returning the values here        cout<<"("<< numerator << "/"<<denominator <<") * ("<< numerator2 <<"/"<< denominator2 <<") = " << c << "/" << d;     cout << "\n";     return 0; }       int main()          {     multiply();     system ("PAUSE"); }```
Why c and d its 0??????
• 02-19-2012
Elysia
Why are you not listening?
Go read up on the command operator, passing by value and passing by reference.
• 02-19-2012
Agnes Roguska
its working:):) thanks
Show 80 post(s) from this thread on one page
Page 3 of 3 First 123