In: Computer Science
C++ code Why my code is not compiling? :(
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
const int CWIDTH = 26;
int main()
{
int choice;
double convertFoC, converCtoF;
double starting, endvalue, incrementvalue;
const int CWIDTH = 13;
do {
cin >> choice;
switch (choice)
{
cin >> starting;
if (starting == 28){
cout << "Invalid range. Try again.";
}
while (!(cin >> starting)){
string garbage;
cin.clear();
getline(cin, garbage);
cout << "Invalid data Type, must be a number. Program terminated." << endl;
return 0;
}
cin >> endvalue;
cin >> incrementvalue;
switch (choice) {
case 1:
cout << "Fahrenheit" << setw(17) << "Celsius" << endl;
for (double calcCelsius = starting; calcCelsius <= endvalue; calcCelsius = calcCelsius + incrementvalue)
{
convertFoC = (5.0 / 9.0) * (calcCelsius - 32.0);
cout << showpoint << fixed << setprecision(2) << calcCelsius << setprecision(2) << setw(21) << convertFoC << right;
cout << endl;
}
break;
case 2:
cout << "Celsius" << setw(CWIDTH) << "Fahrenheit\n";
for (double calcFahrenheit = starting; calcFahrenheit <= endvalue; calcFahrenheit = calcFahrenheit + incrementvalue)
{
converCtoF = ((9.0 / 5.0) * calcFahrenheit) + 32.0;
cout << setw(CWIDTH) << showpoint << fixed << setprecision(1) << calcFahrenheit << fixed << setprecision(1) << setw(CWIDTH) << converCtoF << right;
cout << endl;
}
case 3:
cout << " thank you";
break;
} while (choice !=3);
return 0;
}
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
const int CWIDTH = 26;
int main()
{
int choice;
double convertFoC, converCtoF;
double starting, endvalue, incrementvalue;
const int CWIDTH = 13;
do
{
cin >> choice;
cin >> starting;
if (starting == 28)
{
cout << "Invalid range. Try again.";
continue;
}
cin >> endvalue;
cin >> incrementvalue;
switch (choice)
{
case 1:
cout << "Fahrenheit" << setw(17) << "Celsius" << endl;
for (double calcCelsius = starting; calcCelsius <= endvalue; calcCelsius = calcCelsius + incrementvalue)
{
convertFoC = (5.0 / 9.0) * (calcCelsius - 32.0);
cout << showpoint << fixed << setprecision(2) << calcCelsius << setprecision(2) << setw(21) << convertFoC << right;
cout << endl;
}
break;
case 2:
cout << "Celsius" << setw(CWIDTH) << "Fahrenheit\n";
for (double calcFahrenheit = starting; calcFahrenheit <= endvalue; calcFahrenheit = calcFahrenheit + incrementvalue)
{
converCtoF = ((9.0 / 5.0) * calcFahrenheit) + 32.0;
cout << setw(CWIDTH) << showpoint << fixed << setprecision(1) << calcFahrenheit << fixed << setprecision(1) << setw(CWIDTH) << converCtoF << right;
cout << endl;
}
break;
case 3:
cout << " thank you";
break;
}
} while (choice != 3);
return 0;
}
.
Output:
.