I did most of this program, but it has a couple of problems. Every time I get to the end of the program the Highest numerator is always five regardless of what I entered. The next problem is the Highest denominator entered does not show up. Instead a lot of numbers show up. The program also allows me to enter a 0 for the denominator. The last thing is I don't know if the positions are right.

It is suppose to have a main() function that declares an array of 5 Fraction objects. Prompt the user for values for each field of each Fraction. It is not suppose allow the user to enter a value of 0 for the denominator of any Fraction; for each Fraction, continue to prompt the user for a denominator value until a non-zero value is entered. It is also suppose to Display the numerator and denominator for each of the five Fraction objects. Then display the value of and array position of the highest numerator, and the value of and array position of the highest denominator.
Please help me!

// Shaneka Hall
// Class Definition
// Assignment1
// 16 January 2005

   class Fraction
	    int numerator;
		int denominator;
// Shaneka Hall
// CS 3358
// Mr.Basilio
// Assignment 2
// 23 January 2005

#include <iostream.h>
#include "ch01CsPrj.h"

int main()
    const int FRACTIONSIZE = 5; 
    Fraction test [FRACTIONSIZE];
	int x = 0; // counter variable

	int highestnum = 0;
	int highestden = 0;

	 for (x = 0; x < FRACTIONSIZE; x++)

	  cout<<"Enter a value for numerator";
	  cout<<"Enter a value for denominator";
	    while(test[x].denominator ==0)
			cout<<"You cannot enter a 0 for the demonminator.  Please enter a non-zero number :";
		   if(test[x].numerator > highestnum)
		   highestnum = test[x].numerator;
		   for(x =0; x < highestnum; x++)	
			if(test[x].denominator > highestden)
			 highestden = test[x].denominator;

			 for(x =0; x < highestden; x++)
			cout<<"The value of the highest numerator is "<<highestnum<<endl;
			cout<<"The array positon of the higest numerator is" <<&highestnum<<endl;

				cout<<"The value of the higest denomenator is "<<highestden<<endl;

				cout<<"The array positiion the higest denominator is "<<&highestden<<endl;

 return 0;

Remove unnecessary parts (ie. unrelated to your problem) from the program and then post it here. Many people are unwilling to download attachments because it's an inconvenience when most of the time we can tell you what the problem is at a glance.

One thing that I did was change <iostream.h> to <iostream> took out a lot of errors. With this I included using namespace std; before you entered the main() function. Then when I tried to compile it said no new line in your class 'Fraction' so I put cout << "\n"; in and it compiled and worked. but when I compiled it there were some bugs in it, that I haven't looked for yet. I hope that helpped a little.

This article has been dead for over six months. Start a new discussion instead.