Sunday 17 July 2011

First program

Created my first C++ program which basically converts Celsius into Fahrenheit..

Heres the source code:

// Convert temperature from Celsius to Fahrenheit & vice versa
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>

int main(int nNumberofArgs, char* pszArgs[])
{
using namespace std;

string choice = "y";
char CF;
char C;
char F;

cout << "Assign Celsius to a key" << endl; 
cin >> C;
cout << "Assign fahrenheit to a key" << endl; 
cin >> F;

cout << endl; while (choice == "y")
 {
           cout << "Which do you wish to convert?";
cout << endl;
   
          cin >> CF;
          if (CF == C)
{
 // Celsius
 double celsius;
  cout << "Enter the temperature in Celsius: ";
  cin >> celsius;

// Factor
double factor;
factor = 180.0;

// Celsius to fahrenheit using factor
double fahrenheit;
fahrenheit = factor * celsius/100.0 + 32.0;

// Output the results on-screen
cout << "Fahrenheit value is: "; 
cout << fahrenheit << endl; cout << endl; 
}
 else
 {
 double Fahrenheit;
             cout << "Enter the temperature in fahrenheit: ";
            cin >> Fahrenheit;

double Celsius;
Celsius = (Fahrenheit - 32)*5/9;

cout << "Celsius value is: ";
         cout << Celsius << endl;
         cout << endl;
 }
  cout << "Would you like to start again?" << endl;
  cin >> choice;
system("cls");
}
system("PAUSE");
return 0;
}


 Click to animate

26 comments:

  1. nice one i cant even use java sometime

    ReplyDelete
  2. dayme son it takes a lot of coding for somthing so small

    ReplyDelete
  3. I Live in a dorm with Americans...this could come in handy :D

    +follow

    ReplyDelete
  4. Nice stuff man, I tried to self-teach C++ some time ago, I gave up way before this stage though.

    Awesome blog, very interested in coding so followed.

    ReplyDelete
  5. wow...im a total nut for this kinda stuff, i can only admire you

    ReplyDelete
  6. I can't even program my TV.

    ReplyDelete
  7. Definitely foreign to me, I wish I could understand it! Nice stuff, I admire you for creating this yourself! +1

    ReplyDelete
  8. Dude, this is so cool! That coding looks absurdly difficult >.>.

    ReplyDelete
  9. oh cool! I really need to learn C++...

    ReplyDelete
  10. Nice! Definitely better than I could do at this point.
    +followed

    ReplyDelete
  11. Nice.

    Except it's useless because Fahrenheit is a worthless unit. ;)

    ReplyDelete
  12. Nice as code man, I aspire to learn this stuff when I can be bothered haha

    ReplyDelete
  13. I laughed out loud at Exiro's comment. Very cool nonetheless! +1

    ReplyDelete
  14. Well, looks like my dreams of coding went out the window. What a bitch for something so simple!

    ReplyDelete
  15. haha what a trivial thing to create, but big ups anyway because youre dabbling in the black magic of this era by learning how to program ;)

    ReplyDelete
  16. This comment has been removed by the author.

    ReplyDelete
  17. @ Exiro, from a chemical engineer's perspective, Fahrenheit is much more sensible scale than Celsius. Celsius degrees encompass a much larger temperature values, while Fahrenheit allows people to be much more precise with explaining temperatures-ideal for candy-making, cooking, and scientists. Rankine is the temperature scale that, in my opinion, makes the most sense. Unfortunately, the popularity of Celsius due to the easy 0-100 water scale outweighs the inconveniences of the temperature scale.

    This all being said, Fahrenheit is just as easy when you grow up with it.

    ReplyDelete
  18. good basic coding to start! +followed

    ReplyDelete
  19. I'm a python man myself. I've been thinking about getting into C++.

    ReplyDelete
  20. I was thinking about learning Java or else,˛but when I was a young boy I used to learn a bit of C++. Sadly I don't remember anything...

    ReplyDelete
  21. Well done! I'm learning objective C, myself :)

    ReplyDelete
  22. now program something that will fill my bank account with money

    ReplyDelete
  23. not bad, did something similar myself not too long ago :)

    +followed

    www.whatshouldibuytoday.blogspot.com

    ReplyDelete
  24. Dude that's impressive!
    I work with tons of engineers and can't understand any of that stuff

    +followed! :D

    ReplyDelete
  25. Always wanted to learn this stuff, thanks for inspiring!

    ReplyDelete