hey, this program is supposed to calculate fractions, and I feel that I have most of the code down, but I can't get past the
fractions.cpp:50: error: expected primary-expression before 'char'
error, its probably something misicule, but I can't get it for the life of me. The error is in the main function. heres my code. THANK YOU SO MUCH IN ADVANCE!!!
#include <iostream>
#include <string>
using namespace std;
void menu (char symbol);
void addFractions(int& a,int& b,int& c,int& d,int& numerator,int&
denominator);
void subtractFractions(int& a,int& b,int& c,int& d,int& numerator,int&
denominator);
void multiplyFractions (int& a,int& b,int& c,int& d,int& numerator,int&
denominator);
void divideFractions (int& a,int& b,int& c,int& d,int& numerator,int&
denominator);
int main()
{
int a, b, c, d;
int numerator;
int denominator;
char symbol;
cout << "first, we will need your numerators/denominators." << endl;
cout << "What is your first fractions numerator?" << endl;
cin>> a;
cout << "What is your first fractions denominator?" << endl;
cin >> b;
cout << "What is your second fractions numerator?" << endl;
cin >> c;
cout << "What is your second fractions denominator?" << endl;
cin >> d;
while (d == 0 || b == 0)
{
if (d == 0)
{
cout << "Your second fraction has a 0 in the denominator, what would" <<
" you like to change it to?" << endl;
cin >> d;
}
if (b == 0)
{
cout << "Your first fraction has a 0 in the denominator, what would" <<
" you like to change it to?" << endl;
cin >> b;
}
}
menu (char symbol);
return 0;
}
void menu(char symbol)
{
int a, b, c, d;
int numerator, denominator;
cout << "Have fractions that need solving??" << endl;
cout << "Well, luckily for you, you chanced upon a fractions calculator"
<< endl;
cout << "First, we will need the operation you wish to perform." <<
endl;
cout << "choose one of the following: + (addition), - " <<
"(subtraction), * (multiplication), and finally / (division)." << endl;
cin >> symbol;
cout << endl;
switch (symbol)
{
case '*':
multiplyFractions(a,b,c,d,numerator, denominator);
cout << "Answer is " << numerator << "/" << denominator << endl;
break;
case '/':
divideFractions(a,b,c,d,numerator, denominator);
cout << "Answer is " << numerator << "/" << denominator << endl;
break;
case '+':
addFractions(a,b,c,d,numerator, denominator);
cout << "Answer is " << numerator << "/" << denominator << endl;
break;
case '-':
subtractFractions(a,b,c,d,numerator, denominator);
cout << "Answer is " << numerator << "/" << denominator << endl;
break;
default:
cout << "Invalid input, pay better attention next time." <<
endl;
}
}
void addFractions (int& a,int& b,int& c,int& d,int& numerator,int&
denominator)
{
int temp;
temp = b*d;
numerator = (temp/b*a)+(temp/d*c);
denominator = temp;
}
void subtractFractions (int& a,int& b,int& c,int& d,int& numerator,int&
denominator)
{
int temp;
temp = b*d;
numerator = (temp/b*a)-(temp/d*c);
denominator = temp;
}
void multiplyFractions(int& a,int& b,int& c,int& d,int& numerator,int&
denominator)
{
numerator = (a*c);
denominator = (b*d);
}
void divideFractions(int& a,int& b,int& c,int& d,int& numerator,int&
denominator)
{
numerator = (a*d);
denominator = (b*c);
}