Im currently working on a project for a beginner c++ class in school and im making a basic converter program using switches. I have set it up so when the user enters a specific number, it brings them to the conversion for that medium, such as pressing 1 to get to the length conversions, it is very much unfinished, but as im testing it, entering numbers that will output a number with a decimal point results in a rounded number, even when im using double-type variables. I've combed through the code and any other things online about what could be incorrect but decided it might be a good idea to ask you guys.
#include <iostream> using namespace std; int main() { int input1 = 0, value = 0, x; double rate = 0; cout << "Welcome to the Converter Program\n" << endl; do { cout << "Please select one of the 3 conversions available:\n()()()()()()()\n< 1-Length >\n" << "< 2-Weight >\n< 3-Tempurature >\n\n()()()()()()()\n"; cin >> input1; if (input1 == 1) { cout << "Please enter your desired length conversion\n()()()()()()()\n<1-Inch to Foot>\n<2- Foot to Yard>\n<3-Foot to Miles>\n ()()()()()()()\n\n"; cin >> x; switch (x) { case 1: cout << "Please enter your inches value to convert to feet\n-------------------------------------------------\n"; cin >> value; rate = value / 12; cout << value << "Inches =" << rate << "Feet.\n\n\n\n"; break; case 2: cout << "Please enter your ft value to convert to yards\n-------------------------------------------------\n"; cin >> value; rate = value / 3; cout << value << "Feet =" << rate << "Yards.\n\n\n\n"; break; } } } while (1 > 0); }''' https://stackoverflow.com/questions/65930452/issues-with-switch-based-converter-program-output-isnt-showing-decimal-points January 28, 2021 at 11:03AM
没有评论:
发表评论