Hi, im new to c++ and im trying to better myself..
i am trying to make a simple calculator and wanted to be able to make sure the user only can enter a int at some points and double at others. I've tried a few different If statements however they haven't worked so far. Here's some of my code
thanks for any help.Code:int quad() { .. .. //local variables .. .. double a,b,c,d,e,f,g; .. .. .. .. char cLoop; //function .. .. do {cout << "This is the page for the quadratic formula (aX2+bX+c)"; .. .. cout << "\n Please enter a: "; .. .. cin >> a; //Want it to check here .. .. cout << "\n Please enter b: "; .. .. cin >> b; .. .. cout << "\n Please enter c: "; .. .. cin >> c; .. .. d = pow(b,2) - 4 * a * c; .. .. if (d < 0) .. .. .. .. { .. .. .. .. .. .. cout << "\nNo Real Roots!"; .. .. .. .. } .. .. else if (d = 0) .. .. .. .. { .. .. .. .. .. .. cout << "One Real Root: "; .. .. .. .. .. .. e = -b + ((sqrt(d)) / 2 * a); .. .. .. .. .. .. cout << "\n Your Root Is" << e; .. .. .. .. } .. .. else .. .. .. .. { .. .. .. .. .. .. cout << "Your Roots Are: "; .. .. .. .. .. .. f = -b + ((sqrt(d)) / 2 * a); .. .. .. .. .. .. g = -b - ((sqrt(d)) / 2 * a); .. .. .. .. .. .. cout << "\nX = " << f; .. .. .. .. .. .. cout << "\nX = " << g; .. .. .. .. } .. .. .. .. cout << "Do you wish to do this again? Y or N.\n"; .. .. .. .. cin >> cLoop; .. .. } while (cLoop == 'Y' || cLoop == 'y'); .. .. return 0; }



2Likes
LinkBack URL
About LinkBacks



