How would I get a number to show decimal points up to 1? I have code written (I know it's bad, sorry, I'm a new C++ stud

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

How would I get a number to show decimal points up to 1? I have code written (I know it's bad, sorry, I'm a new C++ stud

Post by answerhappygod »

How would I get a number to show decimal points up to 1? I have
code written (I know it's bad, sorry, I'm a new C++ student) but
cannot figure out how to make my number display 75.0 instead
of 75. I'll attach a screenshot of what it shows currently. It
shows the numbers 75 and 50. I need it to show 75.0 and 50.0
instead. I will provide my current code below too.
How Would I Get A Number To Show Decimal Points Up To 1 I Have Code Written I Know It S Bad Sorry I M A New C Stud 1
How Would I Get A Number To Show Decimal Points Up To 1 I Have Code Written I Know It S Bad Sorry I M A New C Stud 1 (971 Bytes) Viewed 79 times
#include <iostream>
#include <iomanip>
#include<string>
using namespace std;
int givenTempatures = 0;
double storedData[3][10] = {};
void showMenu()
{
cout << "\n";
cout <<
"--------------------------------------------- \n";
cout << " \t\tMENU \t \n";
cout <<
"--------------------------------------------- \n";
cout << " 1. Convert Fahrenheit to Celsius
(Centigrade)\n";
cout << " 2. Convert Fahrenheit to
Kelvin\n";
cout << " 3. Display Data\n";
cout << " 4. Quit\n";
}
void showCelsius()
{
if (givenTempatures >= 10) {
cout << "\nError: You
have already entered 10 tempatures to convert!";
return;
}
double givenTemp;
double celsiusFinal;
double kelvinFinal;
cout << "\nEnter a Fahrenheir
tempature to convert to Celsius: ";
cin >> givenTemp;
celsiusFinal = (givenTemp - 32) * 5 /
9;
kelvinFinal = (5.0 / 9) * (givenTemp - 32) +
273.15;
cout << round(givenTemp *
10)/10 << " Fahrenheit = " << round(celsiusFinal *
10)/10 << " Celsius\n";
givenTempatures += 1;
storedData[0][givenTempatures - 1] =
round(givenTemp * 10)/10;
storedData[1][givenTempatures - 1] =
round(celsiusFinal * 10)/10;
storedData[2][givenTempatures - 1] =
round(kelvinFinal * 10)/10;
}
void showKelvin()
{
if (givenTempatures >= 10) {
cout << "\nError: You
have already entered 10 tempatures to convert!";
return;
}
double givenTemp;
double kelvinFinal;
double celsiusFinal;
cout << "\nEnter a Fahrenheit
tempature to convert to Kelvin: ";
cin >> givenTemp;
kelvinFinal = (5.0 / 9) * (givenTemp
- 32) + 273.15;
celsiusFinal = (givenTemp - 32) * 5 /
9;
cout << round(givenTemp *
10)/10 << " Fahrenheit = " << round(kelvinFinal *
10)/10 << " Kelvin\n";
givenTempatures += 1;
storedData[0][givenTempatures - 1] =
givenTemp;
storedData[1][givenTempatures - 1] =
round(celsiusFinal*10)/10;
storedData[2][givenTempatures - 1] =
round(kelvinFinal*10)/10;
}
void displayData()
{
int i, j;
for (i = 0; i < 3; i++)
{
if (i == 0) {
cout << "Fahrenheit:
";
};
if (i == 1) {
cout << "Celsius:
";
};
if (i == 2) {
cout << "Kelvin:
";
}
for (j = 0; j <
givenTempatures; j++)
{
cout << "\t" <<
storedData[j];}
cout << endl;
}
}
int main()
{
do {
showMenu();
int Choice;
cout << "Enter your
choice (1-4): ";
cin >>
Choice;
switch
(Choice)
{
case 1: showCelsius();
break;
case 2: showKelvin();
break;
case 3: displayData();
break;
case 4: return 0;
break;
default: cout <<
"Invalid Choice."; break;
}
} while (true);
return 0;
}
Fahrenheit: 75 50
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply