# Adding a series of fractions

 Patricia Ghann · January 6, 2015 Hello Bucky, Happy New Year. Please I want to write a program in c++ to add a series of fractions and am finding it difficult so I need your help please. I want to add for example 1/3+3/5+5/7+7/9+9/11+...............+97/99.

## Replies

- page 2

 c student · January 7, 2015 you may want to declare a struct fraction which contains members num and den.  when you request input, you could ask how many fractions they may want to enter in which sets the amount of loops.  you will need to input the numerator and denominator separately for each fraction. once that's done, you may want to create a loop with a function containing a fraction-adding algorithm.  > fractionResult.num = fraction1.num*fraction2.den + fraction2.num*fraction1.den> fractionResult.den = fraction1,den*fraction2.denan example: if you want to calculate 1/3 + 3/5:> fractionResult.num = 1*5+3*3 = 5+9 = 14> fractionResult.den = 3*5 = 15resulting in a fraction result struct representing 14/15, save the value and add on the next input fraction Patricia Ghann · January 7, 2015 Please help. Don't know what is going on now. I have modified the code and its not doing what its meant to do.#includeusing namespace std;int main(){int num = 0;int den = 0;float fraction;fraction =float(num)/float(den);int numberOfFractionEntered = 0;double sum = 0;The court<< "Enter first fraction or -1 to quit" <> fraction;while (fraction !=-1){//sum = sum + fraction;//numberOfFractionEntered++;cin>>num;cout<> den;cout<>fraction;sum = sum + fraction;numberOfFractionEntered;}cout<using namespace std;Hello, what seems to be the problem? This program builds and runs alright, but its not doing what I want. I need help have to submit by Thursday. Thanks.#includeusing namespace std;int main(){int num = 1;int den = 3;float fraction(num/den);int numberOfFractionEntered = 0;int sum = 0;cout<< "Enter first fraction or -1 to quit" <> fraction;while (fraction < 1/3){sum = sum + fraction;numberOfFractionEntered++;cout<< "Enter next fraction or -1 to quit" <>fraction;}cout<
• 1
• 2

## C++

118,444 followers