View previous topic :: View next topic |
Author |
Message |
JakSplitter Expert Cheater
Reputation: 0
Joined: 31 Aug 2006 Posts: 196
|
Posted: Thu Nov 15, 2007 7:44 pm Post subject: [C++] Fahrenheit To Celsius Converter |
|
|
Well, i recently picked up on C++ again so i decided to make a little Fahrenheit To Celsius Converter.
|
|
Back to top |
|
 |
CRISISxCupid I post too much
Reputation: 1
Joined: 09 Jun 2007 Posts: 2256
|
Posted: Thu Nov 15, 2007 7:46 pm Post subject: |
|
|
Thank you
I needed it for homework O.o
_________________
|
|
Back to top |
|
 |
JakSplitter Expert Cheater
Reputation: 0
Joined: 31 Aug 2006 Posts: 196
|
Posted: Thu Nov 15, 2007 7:47 pm Post subject: |
|
|
Lol np.
|
|
Back to top |
|
 |
MegaForum Grandmaster Cheater
Reputation: 0
Joined: 20 Aug 2007 Posts: 558
|
Posted: Thu Nov 15, 2007 8:04 pm Post subject: |
|
|
These are very useful . Good thing to start out on for practice.
|
|
Back to top |
|
 |
JakSplitter Expert Cheater
Reputation: 0
Joined: 31 Aug 2006 Posts: 196
|
Posted: Thu Nov 15, 2007 8:15 pm Post subject: |
|
|
Lol thanks.
|
|
Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Fri Nov 16, 2007 7:27 am Post subject: |
|
|
What's the point releasing only the exe? -> Of course someone would need the actual program, but I bet they would have Googled it if they needed it. If you want ppl to comment your programming habits, post the source.
btw.. W/o source I can see at least one mistake. Your program gets stuck into a loop if you input a char. So, make a check.
|
|
Back to top |
|
 |
Trow Grandmaster Cheater
Reputation: 2
Joined: 17 Aug 2006 Posts: 957
|
Posted: Fri Nov 16, 2007 8:51 am Post subject: |
|
|
is it that educational to show your ability to do *9/5+32 in C++...?
_________________
Get kidnapped often. |
|
Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Fri Nov 16, 2007 9:03 am Post subject: |
|
|
blland wrote: | is it that educational to show your ability to do *9/5+32 in C++...? |
The purpose of teaching small things such as these is not the equation in the background, but managing input and output.
Edit: Yes, you shold post the source that way we can tell you what you are doing wrong.
Last edited by Flyte on Fri Nov 16, 2007 9:04 am; edited 1 time in total |
|
Back to top |
|
 |
Losplagos Expert Cheater
Reputation: 0
Joined: 21 Mar 2006 Posts: 172 Location: Knee deep in a c++ book
|
Posted: Fri Nov 16, 2007 9:03 am Post subject: |
|
|
You should really post your source code. I will probly post mine if i feel like updating it.
EDIT here is my source.
Code: |
#include <iostream>
int main()
{
int p;
double t;
double x;
int loop = 0;
do
{
std::cout << "Hello enter 1 to continue 0 to quit " << std::endl;
std::cin >> p;
switch(p)
{
case 1:
std::cout << "Enter number in Fahrenheit" << std::endl;
std::cin >> t;
x=(t-32) * 5 / 9;
std::cout << "The answer in celsius is: " << x << std::endl;
break;
case 0:
std::cout << "Good bye";
loop = 1;
break;
default:
std::cout << "invalid input";
break;
}
}while(loop == 0);
}
|
Pretty bad but i just cooked it up with lack of sleep.
_________________
Earthbound = 31337 |
|
Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Fri Nov 16, 2007 12:36 pm Post subject: |
|
|
Losplagos wrote: | You should really post your source code. I will probly post mine if i feel like updating it.
EDIT here is my source. | - What happens if an user inputs a letter or a long number (eg. 23792374982374923749723974)?
- It gets stuck into a loop.
Btw.. You've improved your coding abilities a bit since last time :P
|
|
Back to top |
|
 |
Losplagos Expert Cheater
Reputation: 0
Joined: 21 Mar 2006 Posts: 172 Location: Knee deep in a c++ book
|
Posted: Fri Nov 16, 2007 4:20 pm Post subject: |
|
|
Jani wrote: | Losplagos wrote: | You should really post your source code. I will probly post mine if i feel like updating it.
EDIT here is my source. | - What happens if an user inputs a letter or a long number (eg. 23792374982374923749723974)?
- It gets stuck into a loop.
Btw.. You've improved your coding abilities a bit since last time  |
I was just showing him a basic example. And thanks
edit:
OK here is the better source that fixes the letter problem or long number.
Code: | #include <iostream>
int quitMessage();
int main()
{
int p;
double t;
double x;
int loop = 0;
do
{
std::cout << "Hello enter 1 to continue 0 to quit " << std::endl;
std::cin >> p;
while(std::cin.fail())
{
std::cout << "You did not input a number. Try again: "; // Error msg.
std::cin.clear(); // Clear failbit
std::cin.sync(); // Sync the stream
std::cin >> p; // Try again
}
switch(p)
{
case 1:
std::cout << "Enter number in Fahrenheit 0 to quit" << std::endl;
std::cin >> t;
while(std::cin.fail())
{
std::cout << "You did not input a number. Try again: "; // Error msg.
std::cin.clear(); // Clear failbit
std::cin.sync(); // Sync the stream
std::cin >> t; // Try again
}
x=(t-32) * 5 / 9;
std::cout << "The answer in celsius is: " << x << std::endl;
break;
case 0:
std::cout << "Good bye";
loop = 1;
break;
default:
std::cout << "invalid input";
break;
}
}while(loop == 0);
return quitMessage();
}
int quitMessage()
{
std::cout << "Bye" << std::endl;
return EXIT_SUCCESS;
} |
If you need help with my example for it please tell me jacksplitter and I will add one with comments.
edit2:
Here im doing the formula with a function and commented my code much better.
Code: | #include <iostream>
int quitMessage();
double makeula(double a);
int main()
{
// My variables i could use pointers here but it does'nt matter
int p;
double t;
int loop = 0;
do
{
std::cout << "Hello enter 1 to continue 0 to quit " << std::endl;
std::cin >> p;
while(std::cin.fail())
{
std::cout << "Invalid input "; // Error msg.
std::cin.clear(); // Clear failbit
std::cin.sync(); // Sync the stream
std::cin >> p; // Try again
}
switch(p) //this is much easyer than using nested if commands
{
case 1:
std::cout << "Enter number in Fahrenheit 0 to quit" << std::endl;
std::cin >> t;
while(std::cin.fail())
{
std::cout << "You did not input a number. Try again: "; // Error msg.
std::cin.clear(); // Clear failbit
std::cin.sync(); // Sync the stream
std::cin >> t; // Try again
}
// one way x=(t-32) * 5 / 9; //The formula
std::cout << "The answer in celsius is: " << makeula(t) << std::endl;
break;
case 0:
std::cout << "Good bye";
loop = 1; // break the do while loop
break;
default:
std::cout << "invalid input";
break;
}
}while(loop == 0);
return quitMessage();
}
int quitMessage() // a simple function to do the quit message i could probly use a function for the formula too
{
std::cout << "Bye" << std::endl;
return EXIT_SUCCESS; // EXIT_SUCCESS is easyer
}
double makeula(double a) // doing the formula with a function
{
a=(a-32) * 5 / 9; //Some say you should use functions for almost everything
return a; //returns the rusult of the formula on the line before this
} |
Hope you learn something from it
_________________
Earthbound = 31337 |
|
Back to top |
|
 |
Ztaks Newbie cheater
Reputation: 0
Joined: 18 Nov 2007 Posts: 16
|
Posted: Sun Nov 18, 2007 3:57 pm Post subject: |
|
|
that can be much more efficient O_O
_________________
I'm in your server scanning for vulnerabilities ^^ |
|
Back to top |
|
 |
TheSorc3r3r I post too much
Reputation: 0
Joined: 06 Sep 2006 Posts: 2404
|
Posted: Sun Nov 18, 2007 6:59 pm Post subject: |
|
|
lol losplagos, why don't you just put 'using namespace std' at the top and save yourself a lot of typing?
lol calvin, get it through your head that C++ is not efficient ;_;
_________________
Don't laugh, I'm still learning photoshop! |
|
Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Mon Nov 19, 2007 4:09 am Post subject: |
|
|
TheSorc3r3r wrote: | lol losplagos, why don't you just put 'using namespace std' at the top and save yourself a lot of typing? | Because not everyone wants to destroy that feature of C++. C is freaking annoying when there's no namespaces -> You just can't name your functions whatever you want. Actually I'd recommend ppl NOT to put that "using namespace std" at the top, so they wouldn't mix their own and std functions. You should code something a bit "bigger" and you'd notice that namespaces are so <3.
PS. Besides, typing 5 extra letter won't take so long.
|
|
Back to top |
|
 |
|