d2jsp
Log InRegister
d2jsp Forums > Off-Topic > General Chat > Homework Help > C++ Computer Programming > Need Help With Simple Program
Add Reply New Topic New Poll
Member
Posts: 2,252
Joined: Jan 7 2008
Gold: 0.00
Feb 14 2014 06:11pm
I'm having trouble with making a nested if-else program for my computer programming class, I really need some help with getting the variables set up and I believe I can work it out from there, but as for right now I am stuck.

http://www.uwplatt.edu/csse/courses/CS143/prog1.html

here are the guidelines please pm me if you can help! I need to have this done before 10 PM tonight and I can provide some FG is someone is really helpful in getting me going the right direction.

I have some of the code written but I am a complete newbie so it could be all garbage.

Thanks!
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';

float 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 << " miles is "
<< amount * MILES_PER_KM << " kilometers.";
}
}
return 0;
}


This post was edited by bensfriend1 on Feb 14 2014 06:12pm
Member
Posts: 28,331
Joined: Jun 9 2007
Gold: 11,700.00
Feb 14 2014 06:58pm
try http://forums.d2jsp.org/forum.php?f=122

what i am spotting for starters is that you forget to allow for 'amount' being zero
and you need to have an 'else' clause to deal with the 'amount' being less than zero

This post was edited by brmv on Feb 14 2014 06:59pm
Member
Posts: 2,252
Joined: Jan 7 2008
Gold: 0.00
Feb 14 2014 07:03pm
Quote (brmv @ Feb 14 2014 06:58pm)
try http://forums.d2jsp.org/forum.php?f=122

what i am spotting for starters is that you forget to allow for 'amount' being zero
and you need to have an 'else' clause to deal with the 'amount' being less than zero


I posted there too, and I know about the else I just havent gotten that far yet because I am so frustrated.
Go Back To Homework Help Topic List
Add Reply New Topic New Poll