-
February 14th, 2014, 08:09 PM
#1
Need urget c++ help (nested if-else)
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.
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 = 0;
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;
}
-
February 14th, 2014, 10:10 PM
#2
Re: Need urget c++ help (nested if-else)
//---------------------------------------------------------------------
//
// 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 and an amount (K, M, F, C): " ;
cin >> unit >> 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 - FREEZING_F ) * CELSIUS_PER_FAHR << " 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 * FAHR_PER_CELSIUS + FREEZING_F << " F." ;
}
else
{
cout << "UNABLE TO PROCESS: " << unit
<< " is not a recognized measurement." << endl;
cout << "Please enter either K, M, F, or C." << endl;
}
return 0;
}
Even tho you guys werent very helpful, here is the finished product if you were curious
-
February 15th, 2014, 06:52 AM
#3
Re: Need urget c++ help (nested if-else)
Even tho you guys werent very helpful
Some of us live in countries with different time-zones to you. I've only picked up this thread 10 hours after you posted it and I would certainly have provided some guidance for you.
It's no good saying that you have an assignment to complete by a certain time and expect immediate help. We all here will provide what we can to help but we have our jobs as well.
PS as per your first post, please use code tags when posting code. The code in your post #2 is just about unreadable.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
February 15th, 2014, 02:51 PM
#4
Re: Need urget c++ help (nested if-else)
Originally Posted by 2kaud
Some of us live in countries with different time-zones to you. I've only picked up this thread 10 hours after you posted it and I would certainly have provided some guidance for you.
It's no good saying that you have an assignment to complete by a certain time and expect immediate help. We all here will provide what we can to help but we have our jobs as well.
PS as per your first post, please use code tags when posting code. The code in your post #2 is just about unreadable.
I can understand that certain people couldnt read it, but it had over 50 views before the deadline and nobody offered so much as a tid bit of help. I meant to post the second one in code block but i simply forgot.
-
February 15th, 2014, 03:11 PM
#5
Re: Need urget c++ help (nested if-else)
Originally Posted by bensfriend1
I can understand that certain people couldnt read it, but it had over 50 views before the deadline and nobody offered so much as a tid bit of help. I meant to post the second one in code block but i simply forgot.
A lot of those 'views' would be from guests who aren't actually members of CodeGuru. As I write this post, there are 4 members on line - including you and me - and 753 guests. Also as there are many different forums (covering c#, visual basic, assembler, java .net etc etc) on-line members at any one time may not be c++ people. Although I'm a member and on-line now if a Visual Basic question was asked similar to yours, I would not be in a position to respond as I'm a c++ member.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
February 16th, 2014, 11:50 AM
#6
Re: Need urget c++ help (nested if-else)
Originally Posted by bensfriend1
I can understand that certain people couldnt read it, but it had over 50 views before the deadline and nobody offered so much as a tid bit of help. I meant to post the second one in code block but i simply forgot.
Instead of complaining about others, why don't you have a good look at yourself first? You were able to solve the problem yourself (or at least, without help from anyone here) in 2 hours. Yet you did not want to spend that time and effort before asking for help here. What if somebody would have spend 15 minutes typing a long reply to your OP just before you posted your solution? They would have wasted their time on you, that's what.
There are a lot of very experienced people here who provide their help to anyone free of charge. But you cannot demand to receive help, because no one is obliged to help you. It's all done out of free will. And saying your question is "urgent" does not entitle you to receive more help or receive help faster than anyone else posting here. Your deadline is your problem.
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
-
February 16th, 2014, 01:15 PM
#7
Re: Need urget c++ help (nested if-else)
Originally Posted by bensfriend1
I can understand that certain people couldnt read it, but it had over 50 views before the deadline and nobody offered so much as a tid bit of help.
This is the real world. If you want anybody to cooperate, you need to offer something that would make others be interested in the cooperation. "Urgent assignment" is the worst advertisement to your issue here on the forum. Offering money is the second worst.
When I see another assignment tried to be accomplished by having community involved I always go by, as I'm sure the best favor I can do to a student is leaving him alone facing the problem he is supposed to solve on his own. Ability to accomplish tasks being not relying on anybody is a great skill for your future career, of course if you plan to make one. And this is exactly what assignments are about.
But I always am willing to help in solving real engineer issues, especially the ones that catch me. Yours did not, sorry.
Last edited by Igor Vartanov; February 16th, 2014 at 01:24 PM.
Best regards,
Igor
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|