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; 
 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;
return 0;

 Click to animate


  1. nice one i cant even use java sometime

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

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


  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.

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

  6. I can't even program my TV.

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

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

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

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

  11. Nice.

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

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

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

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

  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 ;)

  16. This comment has been removed by the author.

  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.

  18. good basic coding to start! +followed

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

  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...

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

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

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


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

    +followed! :D

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