gives me 0/0 nomatter what

Page 1 of 1

1 Replies - 380 Views - Last Post: 10 October 2012 - 02:03 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=295023&amp;s=9467e570558bb79d3ab7500c55ca8000&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 iaih105

Reputation: 0
• Posts: 1
• Joined: 10-October 12

gives me 0/0 nomatter what

Posted 10 October 2012 - 01:48 AM

i'm trying to put the input fractions in the right format and the program will give me 0/0 no matter what I put
and when I make the denominator 0, it will give me Floating point exception (core dumped)..
here's the code
```#include <iostream>
#include <iomanip>

using namespace std;

int main ()
{
int numerator;
int numerator_;
int denominator;
int denominator_;
int bignum;
int numpositive;
int denopositive;
int remainder;
char dash;
int check_1;
int check_2;
double mixed;

cout << "Jinsil Han  Assignment#05  Section#1003" << endl;

cout << "Please enter a fraction (numerator / denominator)" << endl;
cin >> numerator >> dash >> denominator;

check_1 = numerator%1;
check_2 = denominator%1;
mixed = numerator/denominator;
numpositive = numerator * -1;
denopositive = denominator * -1;
bignum = numerator/denominator;
remainder = numerator%denominator;

if (denominator = 0)
cout << numerator << dash << denominator << "is an invalid fraction and cannot be reformatted" << endl;
if (numerator = 0)
cout << "0" << endl;
if (check_1 != 0 || check_2 != 0)
cout << mixed << endl;
else if (numerator > 0 && denominator > 0 && numerator < denominator)
cout << right << setw(4) << numerator << " " << dash << " " << left << setw(4) << denominator << endl;
else if (numerator > denominator)
cout << right << setw(4) << bignum << right << setw(4) << remainder << " " << dash << " " << denominator << endl;
else if (numerator < 0 && numpositive < denominator)
cout << right << setw(2) << "-" << left << setw(4) << numpositive << " " << dash << " " << denominator << endl;
else if (numerator < 0 && numpositive > denominator)
cout << right << setw(2) << "-" << left << setw(4) << bignum * -1 << right << setw(4) << remainder << " " << dash << " " << denominator << endl;
else if (denominator < 0 && numerator < denopositive)
cout << right << setw(2) << "-" << left << setw(4) << numerator << left << setw(4) << denopositive << endl;
else if (denominator < 0 && numerator > denopositive)
cout << right << setw(2) << "-" << left << setw(4) << bignum << left << setw(4) << remainder << " " << dash << " " << left << setw(4) << denopositive << endl;
else if (denominator < 0 && numerator < 0)
cout << right << setw(4) << numpositive << " " << dash << " " << left << setw(4) <<  denopositive << endl;
else
cout << right << setw(4) << numerator << " " << dash << " " << left << setw(4) <<denominator << endl;

return 0;
}

```

Is This A Good Question/Topic? 0

Replies To: gives me 0/0 nomatter what

#2 snoopy11

• Engineering ● Software

Reputation: 1022
• Posts: 3,094
• Joined: 20-March 10

Re: gives me 0/0 nomatter what

Posted 10 October 2012 - 02:03 AM

Hi,

lines 34 and 36

if (denominator = 0)

should be

if (denominator == 0)

same goes for line 36 for numerator

Regards

Snoopy.