Quote (AbDuCt @ Feb 14 2014 07:48pm)
Yea I can give it a look when you're done.
Code
//---------------------------------------------------------------------
//
// Name:
//
// Course: CS 1430, Section 2
//
// Purpose: A program that converts between kilometers and miles
// or between Fahrenheit temperature and Celcius.
//
// Input: A character value of 'K' , 'M' , 'F' or 'C'.
// An int or float representing the amount.
//
// Output: A correct conversion between 'K' and 'M' or 'F' and 'C'
// An error message shown for incorrect input of character or
// an error if the temperature or distance is out of range.
//---------------------------------------------------------------------
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
const float MILES_PER_KM = 1.0f / 1.61f;
const float KM_PER_MILE = 1.61f;
const float FREEZING_F = 32.0f;
const float FAHR_PER_CELSIUS = 9.0f / 5.0f;
const float CELSIUS_PER_FAHR = 5.0f / 9.0f;
const float MAX_F_TEMP = 100.0f;
const float MIN_F_TEMP = 0.0f;
char K = 'K';
char M = 'M';
char F = 'F';
char C = 'C';
char unit;
float amount;
int main()
{
cout << " Input a type (K, M, F, C) : ";
cin >> unit;
cout << " Input an amount : ";
cin >> amount;
if ( unit == 'K' )
{
if ( amount > 0 )
{
cout << " Distance " << amount << " kilometers is "
<< amount * MILES_PER_KM << " miles.";
}
else if ( amount <= 0 )
{
cout << " UNABLE TO PROCESS: Negative distances are "
<< " not supported. ";
}
}
else if ( unit == 'M' )
{
if ( amount > 0 )
{
cout << " Distance " << amount << " miles is "
<< amount * KM_PER_MILE << " kilometers.";
}
else if ( amount <= 0 )
{
cout << " UNABLE TO PROCESS: Negative distances are "
<< " not supported. ";
}
}
else if ( unit == 'F' )
{
if ( amount < MAX_F_TEMP && amount > MIN_F_TEMP )
{
cout << " Temperature " << amount << "F is "
<< amount * FAHR_PER_CELSIUS - FREEZING_F << " C.";
}
else
{
cout << " UNABLE TO PROCESS: Temperature too hot or too cold. "
<< endl; cout << " Please enter a temperature comfortable"
<< " when wearing a sweater. " << endl;
}
}
else if ( unit == 'C' )
{
cout << " Temperature " << amount << "C is "
<< amount * CELSIUS_PER_FAHR + FREEZING_F << " F.";
}
else
{
cout << " UNABLE TO PROCESS: " << unit
<< "is not a recognized measurement. ";
}
return 0;
}
Below is Your Output, with line numbers added:
1: Input a type (K, M, F, C) : Input an amount : Distance 2.5 miles is 4.025 kilometers.
**********************************************************
Below is the Correct Output, with line numbers added:
1: Input a type and an amount (K, M, F, C): Distance 2.5 miles is 4.025 kilometers.
**********************************************************
this is what my grader said, how do i get that initial line into one line that accepts two inputs?
This post was edited by bensfriend1 on Feb 14 2014 08:18pm