Wednesday, November 4, 2009

Simple Square Program

this is a simple program to return a square value of the number 27

#include <iostream>


using namespace std;


int Square(int);  // declare that function returns
 // an int and takes an int
int Cube(int);


int main()
{
cout << "The square of 27 is " << Square(27) << endl;
cout << "The cube   of 27 is " << Cube(27)   << endl;
return 0;
}


int Square(int n)
{
return n * n;
}


int Cube(int n)
{
return n * n * n;
}


simple right?

now I want u to make this program to receive user input. meaning, user can input any number, not just 27.

pretty simple right?

C plus plus...declaring variable...and input the value..


as usual, u can copy and paste this..any errors? sort it yourself..this programs just about declaring your variable and asks the user to input the value.

#include <iostream>
#include <string>

using namespace std;

int main()
{
   int age, feet, inches, pounds;
   string hair, eye;

   cout << "My third c++ program.\n\n";
   cout << "Please type your answer to each question" << "followed by ." << endl;
   cout << "What is your age (years)? ";
   cin >> age;
   cout << "\nHow tall are you (ft in)? ";
   cin >> feet >> inches;
   cout << "\nHow much do you weigh (lbs)? ";
   cin >> pounds;
   cout << "\nWhat color is your hair? ";
   cin >> hair;
   cout << "\nWhat color are your eyes? ";
   cin >> eye;

   cout << endl << "\nYou are " << age << " years old, " 
   << feet << " feet " << inches << " inches tall." 
   << "\nYou weigh " << pounds << " pounds,  << " have " 
   << hair << " colored hair and " << eye << " colored eyes." << endl;

   return 0;
}

Friday, October 30, 2009

C plus2 Hello World! hehe




Firstly, welcome to my class..
Caused by many of my student don't know what the hell is C++(coz they learned java all the time)..so i have to create this post in introducing the simple world of C++..so pay attention and dont play facebook in my class...saya takpe..hehe

#include<iostream>

using namespace std;
void main()
{
cout << "Hello World!" << endl;

cout << "Welcome to C++ Programming" << endl; }

actually, you just google it..but I know, you all very busy.. ;-)