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

Saturday, 16 July 2011

Starting C++

I've decided to try and learn a programming language and after an hour or two of researching I've decided to jump in at the deep end with C++, I know some people believe I should start with an easier language like Python or VB but I think with a little dedication C++ will be my perfect language. Wish me luck!