I need some help to be able to input a line of text such as.....
1/2 + 4/3 - (3/2 * 1/3)
and calculate it. I'm trying to use getline but I either don't understand the compiler errors or I don't use the right parameters. Thanks a bunch for the help.
What I want is to read the whole line and be able to store the numerator in fracTop the operator in fracSign, and the denominator in fracBot.
-----------------------------------------------------------------------------------------------------------------
Write a program to do fractional arithmetic. The program should handle the operations of addition, subtraction, multiplication, and division. It should also reduce the answer to its lowest form (e.g. 3/9 should be 1/3). The user should be allowed to enter any number of problems.
#include <istream>
#include <iostream>
#include <cstdio>
#include <cstdlib>
usingnamespace std;
int iNumerator;
char cOperator;
int iDenominator;
//char cPlus[] = "+";
//char cMinus[] = "-";
//char cMult1[] = "x";
//char cMult2[] = "X";
//char cMult3[] = "*";
//char cDivide[] = "/";
int calculator(int iNumerator,int iDenominator)
{
cout <<iNumerator / iDenominator;
//cin.getline(fraction, 30, '/');
//cout << fraction;
}
main()
{
cout << "enter numerator" end1;
cin >> iNumerator;
cout << "enter denominator";
cin >> iDenominator;
calculator(iNumerator,iDenominator);
// or just skip the function (I was writing a calculator not just a divider) and delete function call an just write cout << iNumerator / iDenominator;
// add pause here havn't gotten that far...
// this is good practice for me btw I'm a noob too!!
// Just thought of this, this function will only return an interger value it will NOT include the remainder in the result and it will not return a float value
}
int fracInput()
{
int fracTop, fracBot;
char fracSign;
//string fraction;
char fraction[30]; //since you are using the C style cin.getline you must use a char array
cin.getline(fraction, 30, '/');
cout << fraction;
}
that will let you at least pull something from the input