### Mixed Number Program

I have a program which allows the user to input mixed numbers such as fractions and performs addition, subtraction, division, multiplication operations.

However, I have to modify the program such that it will take negative numbers and the ability to raise x to the y
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212`` ``````#include #include #include using namespace std; struct mixedNumber { int whole, num, denom; void output(); }; void mixedNumber::output() { if(whole == 0) if(num == 0) cout<<0; else cout<> answer.whole>>answer.num>>junk>>answer.denom; } else if(pos2 >= string::npos) { ss<>answer.whole; answer.num = 0; answer.denom = 1; } else { ss<>answer.num>>junk>>answer.denom; answer.whole = 0; } return answer; } char getOperator(string line, int &pos) { string choices[4] = {" + ", " - ", " * ", " / "}; for(int i = 0; i < 4; i++) if( (pos = line.find(choices[i])) < string::npos) break; return pos < string::npos ? line[pos+1] : '\0'; } void process(string line) { mixedNumber one, two, answer; int pos; char op = getOperator(line, pos); if(op == '\0') { cout<<"No operator found! Please re-etner"<
Can anyone give me any input on how to modify the program in order to take in negative numbers?
Any help? I am at a loss to how this program can intake negative numbers and be able to raise the x to the y
What happens when you use a negative number for your input?
it will not properly calculate a mixed number + a mixed number when dealing with fractions

for example, if you input -2/3 + -2/3 it will come out as -1 1/-3

the denominator seems to intake the negative sign
Topic archived. No new replies allowed.