Tuesday, July 14, 2009

Another c++ problem.?

how to create the equivalent of a four-function calculator?the program should ask the user to enter a number, an operator, and another number. and then it should carry out the specified arithmetical operation: adding, subtracting, multiplying or dividing the two numbers.


waa..i'm really not good in c++. somebody please help!


well, the output is suppose to look something like this:


enter first number, operator, second number: 10 / 3


answer = 3.333333


do another (y/n)? y


enter first number, operator, second number: 12 + 100


answer = 112


do another (y/n)?n


that's about it..do help..

Another c++ problem.?
just take an F
Reply:Well, one way that you can do this is to,





read in the line of input from the user,


read in the three various values from the string,


determine the operator from the second input,


then you will be able to determine the answer.
Reply:[sum]


Print "Enter first number, operator, second number: ";


input a, b$, c


answer = a b$ c


print "answer is ";answer


print


input "do another (y/n)?;choice$


if choice$ = "y" then [sum] else end
Reply:#include%26lt;iostream.h%26gt;


#include%26lt;conio.h%26gt;


void main()


{


cout%26lt;%26lt;"Four function Calculator";


char *p;


double num1, num2;


num1=num2=0.0;


char op, continue;


do{


cout%26lt;%26lt;"enter first number, operator, second number: "


cin%26gt;%26gt;p;





while(p[i]!="+" || p[i]!="-" || p[i]!="*" || p[i]!="/")


num1=(num1*10 )+ p[i];


op = p[i];


i++;


while(p[i]!='\0')


num2=(num2*10 )+ p[i];





// now we have got all info


switch(op)


{


case '+':


cout%26lt;%26lt;"answer = "%26lt;%26lt;num1+num2;


break;


case '-':


cout%26lt;%26lt;"answer = "%26lt;%26lt;num1-num2;


break;


case '*':


cout%26lt;%26lt;"answer = "%26lt;%26lt;num1*num2;


break;


case '/':


cout%26lt;%26lt;"answer = "%26lt;%26lt;num1/num2;


break;


default:


cout%26lt;%26lt;"Invalid Operator";


break;


}


cout%26lt;%26lt;"do another (y/n)?";


cin%26gt;%26gt;continue;


}while(continue=='y' || continue=='Y')


}














// please mail me if u find any issues


No comments:

Post a Comment