I just started to read up on C++ programing,
the closest ive been to programing is a few bash and sh linux scripts..
Anyway i have a problem with my "calculator" i can only get it to print out
results with 4 decimals, i want it to be a little more accurate..
Here is the code for my calc:
If i do like 100/7 the result becomes: 100/7 = 14.2857Code:#include <iostream> int main () { // Setting Variables needed for the calc long double value1 = 0; long double value2 = 0; char calc; // Getting the information needed to start calculating cout << "What do you want to calculate? ( Example: 225*5 ) : "; cin >> value1 >> calc >> value2; // Starting to calculate... if ( calc == '*' ) { long double result = value1 * value2; cout << value1 << calc << value2; cout << " = " << result; } if ( calc == '/' ) { long double result = value1 / value2; cout << value1 << calc << value2; cout << " = " << result; } if ( calc == '+' ) { long double result = value1 + value2; cout << value1 << calc << value2; cout << " = " << result; } if ( calc == '-' ) { long double result = value1 - value2; cout << value1 << calc << value2; cout << " = " << result; } return 0; }
Is there a way i havn't thought of that can make it more accurate?
you dont have to give me code for it.. just hint me in the right direction.. i want to learn as much as possible for myself.
And please don't laugh at the code, this is my first actual program (im not counting the "hello world" thing)
edit: changed code according to bumfluff's recomendations



LinkBack URL
About LinkBacks



)