View Full Version: One of my first creations

C++ Learning Community > C++ Creations > One of my first creations


Title: One of my first creations
Description: extremley simple age prog.


ccurtis - February 14, 2005 06:20 PM (GMT)
i wrote this without looking back at my c++ books. and with a few small corections from a few of u guys here it is..

CODE
//Age prog.
#include <iostream>    //Not iostream.h
using namespace std;      

int main()
{
 int a;

 cout <<"what is your age?\n"; //asks for age.
 cin >> a; //alows you to input age.

 if (a < 10)    //if a is less than 10 the following is displayed.
 {
cout <<"Wow you are young\n"; //displayed if the above statement is true.
 }

 else if (a >= 11 && a <= 40)   //if a is greater than or equal to 11 and less than or equal to 40 the following is displayed.
 {
cout <<"Youve got a long life to live\n"; //displayed if the above statement is true.
 }

 else if (a > 40)   //if a is greater than 40 the following is displayed.
 {
cout <<"I feel bad for you...\n"; //displayed if the above statement is true.
 }

 system("pause"); //pauses program before termination.
 return 0;
}

DeAs91 - February 14, 2005 06:30 PM (GMT)
QUOTE (ccurtis @ Feb 14 2005, 06:20 PM)
CODE
#include <iostream>    //Not iostream.h

Not to be rude, but I have nevere seen a comment such as that in a complete program :) But anyway, nice done!

ccurtis - February 14, 2005 06:34 PM (GMT)
that comment actually wasnt from me lol.. a copy and paste error

donprogc++ - February 14, 2005 07:43 PM (GMT)
:lol:

DeAs91 - February 14, 2005 09:04 PM (GMT)
QUOTE (ccurtis @ Feb 14 2005, 06:34 PM)
that comment actually wasnt from me lol.. a copy and paste error

Yeah, I know...I wrote the comment :)

ccurtis - February 14, 2005 10:14 PM (GMT)
lol yes.. all credit to u my friend.

KTC - February 14, 2005 10:24 PM (GMT)
Just to be picky. system( char* ) is defined in <cstdlib>. Do include it if you use that function even if your current compiler / libraries implementation include it in some other header you're using like <iostream> in this case.




* Hosted for free by InvisionFree