I'm still working on this same assignment and have made progress but I'm getting an error when I try to call my addFraction function and have no idea why I'm getting it (hopefully it's something stupid that I'm missing). I get syntax errors in the line where I try to call my addFraction function. The function defentition is:
void addFraction (int numerator1, int denominator1, int numerator2, int denominator2, int& numeratoranswer, int& denominatoranswer) {
// Get common donimator for fractions
numerator1 = numerator1 * denominator2;
denominator1 = denominator1 * denominator2;
numerator2 = numerator2 * denominator1;
denominator2 = denominator2 * denominator1;
// Perform addition on fractions
numeratoranswer = numerator1 + numerator2;
denominatoranswer = denominator1;
}
the line where I get the error from trying to call the function is:
addFraction (int numerator1, int denominator1, int numerator2, int denominator2, int numeratoranswer, int denominatoranswer);
I get 3 errors when I try to compile:
Compiling...
lab04.cpp
C:\Documents and Settings\Scott\My Documents\CS 111\lab04.cpp(51) : error C2144: syntax error : missing ')' before type 'int'
C:\Documents and Settings\Scott\My Documents\CS 111\lab04.cpp(51) : error C2660: 'addFraction' : function does not take 0 parameters
C:\Documents and Settings\Scott\My Documents\CS 111\lab04.cpp(51) : error C2059: syntax error : ')'
Error executing cl.exe.
If you care to look at the whole programs source code:
#include <iostream>
#include <cassert>
using namespace std;
// Prototypes for the functions in this program
void getFraction (int& numerator, int& denominator);
int gcd (int a, int b);
void addFraction (int numerator1, int denominator1, int numerator2, int denominator2, int& numeratoranswer, int& denominatoranswer);
int main () {
// Declare Character Variables
char usercontinue='y';
char operatorsymbol;
char doagain;
// Declare Numerator and Denominator Variables
int numerator1;
int denominator1;
int numerator2;
int denominator2;
int nummeratoranswer;
int denominatoranswer;
do {
// Get operatorsymbol from user to use in switch statement, use do while to verify correct input
do {
cout << "Enter an operation(+,-,*,/): ";
cin >> operatorsymbol;
// Assign value to doagain variable and display error message if appropirate
if ((operatorsymbol == '+') || (operatorsymbol == '-') || (operatorsymbol == '*') || (operatorsymbol == '/'))
doagain = 'n';
else {
doagain = 'y';
cout << "Error: Please input a correction operation symbol" << endl;
}
} while (doagain == 'y');
// Prompt and get numerators and denominators to use in operation
cout << "Enter a numerator and denominator of a fraction seperated by a space: ";
getFraction (numerator1, denominator1);
cout << "Enter a numerator and denominator of a fraction seperated by a space: ";
getFraction (numerator2, denominator2);
addFraction (int numerator1, int denominator1, int numerator2, int denominator2, int numeratoranswer, int denominatoranswer);
/*/ Switch Statement to use correct function for operation type
switch (operatorsymbol) {
case '+':
addFraction (int numerator1, int denominator1, int numerator2, int denominator2, int numeratoranswer, int denominatoranswer);
break;
} */
} while (usercontinue == 'Y' || usercontinue == 'y');
return 0;
}
void getFraction (int& numerator, int& denominator) {
cin >> numerator >> denominator;
}
int gcd (int a, int b) {
assert (b !=0);
int rem = a % b;
while (rem !=0) {
a = b;
b = rem;
rem = a % b;
}
return b;
}
void addFraction (int numerator1, int denominator1, int numerator2, int denominator2, int& numeratoranswer, int& denominatoranswer) {
// Get common donimator for fractions
numerator1 = numerator1 * denominator2;
denominator1 = denominator1 * denominator2;
numerator2 = numerator2 * denominator1;
denominator2 = denominator2 * denominator1;
// Perform addition on fractions
numeratoranswer = numerator1 + numerator2;
denominatoranswer = denominator1;
}
thanks again so much for the help,
-Scott