Hello, I cannot figure out how to resolve two error messages. I have searched on Google and looked for similar cases on this site and a few others. I also tried several steps to debug it, unsuccessfully. This is a homework assignment, so I'd rather not be given the answer, but rather where to look if that's possible. As you will see, it is incomplete and I have "weird" notes to myself, but I don't want to proceed (and probably cause more error) until I get this part figured out.
The 2 error messages are:
1. error C2664: 'Fraction::enterFractionValue' : cannot convert parameter 1 from 'int [3][3]' to 'int []'
2. error C2664: 'Fraction::displayFraction' : cannot convert parameter 1 from 'int [3][3]' to 'int []'
I am marking the errors in the code since I can't copy the line #'s.
I can see that the error messages are saying I'm trying to convert from two subscripts ([] []) to one ([]) but I don't understand how to fix it. I checked the prototype, call, and header for both functions, and they all have the array and then 2 subscripts. I would appreciate any guidance.
I'm using VS10 on Windows XP
Here is my code:
#include "stdafx.h"
#include<iostream>
#include<string>
using namespace std;
// Declaration Section
// Create a 'Fraction' class with three private data fields for whole number, numerator, and denominator.
class Fraction
{
// Declare variables and constants
int wholeNum, numerator, denominator, x;
// Create a constant static public field to hold a slash.
public:
const static char SLASH;
// Create constants for multi-dimensional array subscripts
const static int PARTS = 3;
const static int MAX = 3; // CHANGE THIS ********
// Create an array to hold the Fractions
int fractionArray[PARTS][MAX];
// Create three public member functions.
// Function 1: An 'enterFractionValue()' function.
int enterFractionValue(int[], const int, const int);
// Function 2: A 'reduceFraction()' function.
int reduceFraction(int[], const int, const int);
// function 3: A 'displayFraction()' function.
void displayFraction(int[], const int, const int);
};
// Function 1: An 'enterFractionValue()' function that prompts the user to enter values for the Fraction.
int Fraction::enterFractionValue(int originalFractions[], const int PIECES, const int MOST)
{
for(x = 0; x < MOST; ++x)
{
cout << "Enter a whole number: ";
cin >> fractionArray[0][x];
cout << "Enter a numerator: ";
cin >> fractionArray[1][x];
cout << "Enter a denominator: ";
cin >> fractionArray[2][x];
// Denominator cannot be equivalent to 0.
while(fractionArray[2][x] == 0)
{
cout << "The denominator cannot = 0.";
cout << "Please enter a new denominator: ";
cin >> fractionArray[2][x];
}
}
}
// Function 2: A 'reduceFraction()' function that reduces a Fraction to its proper form.
int Fraction::reduceFraction(int originalFraction[], const int NUMBERS, const int HIGHEST)
{
cout << "This is the function to reduce the fractions." << endl; // DELETE THIS TEST **************************
}
// Function 3: A 'displayFraction()' function that displays the Fraction.
void Fraction::displayFraction(int allFractions[], const int NUM, const int MAXIMUM)
{
cout << "You entered:" << endl;
for(x = 0; x < MAXIMUM; ++x)
cout << fractionArray[0][x] << " " << fractionArray[1][x] << SLASH << fractionArray[2][x] << endl;
}
// The main() function declares a Fraction object and continues to do so until the user enter 0 for the
// whole number and numerator. For each fraction entered, display the fraction, reduce the fraction,
// and display the reduced fraction.
int main()
{
// Declare variables
int x;
// Declare a Fraction object
Fraction aFraction;
// Display welcome message and instructions
cout << "Welcome to the Fraction program." << endl;
cout << "You may enter as many fractions as you'd like and the program will display your fraction and its proper form." << endl;
cout << "You will be prompted to enter a whole number, numerator, and denominator individually for each Fraction." << endl;
cout << "When you have finished and would like to view your results, enter '0' for the whole number and numerator." << endl;
Dude, use code tags for your code next time.
Anyway, to pass a multidimensional array to a function you need to tell the function how large all of the dimensions except for the first one are:
I tried inserting '3' into the prototype, call, and the header, and am still getting the same error messages. Eventually the second subscript (currently called MAX) needs to be a variable based on the number of entries by the user, so I can't use a number there. I hope I'm explaining this correctly. Any other suggestions?