1 Replies - 240 Views - Last Post: 10 October 2012 - 02:03 AM Rate Topic: -----

#1 iaih105  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 768
  • Posts: 2,234
  • 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1