dallas81 0 Newbie Poster

Hi all I am new to this forum and I am having problem using the sort algortihm. My code is suppose to allow the user to enter in fractions and then sort what is entered into the array. The fraction class is only contains the public field numerator and denominator. I can get to enter fractions and display them but I can't sort them or return the min and max values. Thanks in advance for any suggestions that you guys will provide.


#include <iostream>
#include <algorithm>
#include "Fraction.cpp"
using namespace std;


void enterFractionValue(Fraction &position);
void displayFraction(Fraction OneFraction[]);

int main(int argc, char *argv[]) 
{ 
Fraction OneFraction[5]; 
for(int i=0; i<5; i++) 
{ 
enterFractionValue(OneFraction[i]); 
} 
displayFraction(OneFraction); 
} 


void enterFractionValue(Fraction &OneFraction) 
{ 
  cout <<"Enter a value for the numerator: "; 
  cin >> OneFraction.numerator; 
  cout <<"Enter a value for the denominator: "; 
cin >> OneFraction.denominator; 

  while(position.denominator==0) 
  { 
      cout <<"Enter a number other than zero: "; 
      cin >> OneFraction.denominator; 
  } 
  cout << "The fraction entered is: " << OneFraction.numerator << "/" << OneFraction.denominator << endl; 
} 


void displayFraction(Fraction &OneFraction) 
{ 
int selection = 0; 
int i; 

cout <<"Please select from the following options.\n\n" 
<<"Select 1 to view fractions in floating point format\n" 
<<"Select 2 to view the array position of the highest and lowest values\n" 
<<"Select 3 to view the array sorted from smallest to largest\n" 
<<"Select 4 to stop or start over\n"; 
cin >> selection; 

if(selection == 1){ 
for(int i=0; i<5; i++){ 
cout << OneFraction.numerator << "/" << OneFraction.denominator << endl; 
} 
displayFraction(OneFraction);//used to repeat menu operations 
} 

else if(selection == 2){ 
max_element(OneFraction, OneFraction + 5); 

for(i=0; i<5; i++){ 
cout << OneFraction[i] << endl; 
} 
min_element(OneFraction, OneFraction + 5);

for(i=0; i<5; i++){ 
cout << OneFraction[i] << endl; 
} 
displayFraction(OneFraction);//used to repeat menu operations 
} 

else if(selection == 3){ 
[sort(OneFraction, OneFraction + 5); ]

for(i=0; i<5; i++){ 
cout << OneFraction[i] << endl; 
} 
displayFraction(OneFraction); //used to repeat menu operations 
} 
else if (selection == 4){ 
int stop; 
cout << "Are you sure you wish to stop operations?" << endl; 
cout << " 1: Yes" << endl; 
cout << " 2: No"  << endl; 
cin >> stop; 
if (stop == 1){ 
void exit (); 
} 
else if (stop == 2 ){ 
displayFraction(OneFraction); 
} 
} 
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.