>Well, do you think you or someone could be cool and not a smart aleck and show me? =)
Hey, I answered your question, didn't I? The best way to clean up your code is to modularize it:
Code:
#include <cstdio>
#include <iostream>
#include <windows.h>
using namespace std;
void f ( int age )
{
if(age<35)
cout<<"You are young!";
else if(age<65)
cout<<"You are old!";
else if (age<80)
cout<<"You are really old!";
else if (age<100)
cout<<"You are really SUPER old!";
else if (age<=200)
cout<<"How are you STILL kickin!?";
else if(age>200)
cout<<"You've defied God. Congrats!";
}
void console_thingie ( HANDLE& h, WORD& w, CONSOLE_SCREEN_BUFFER_INFO& c )
{
GetConsoleScreenBufferInfo(h, &c);
w = c.wAttributes;
SetConsoleTextAttribute ( h, FOREGROUND_RED| FOREGROUND_INTENSITY );
}
void console_reset ( HANDLE h, WORD w )
{
SetConsoleTextAttribute ( h, w );
}
void do_age ( HANDLE h, WORD w )
{
int age;
cout<<"Now enter your age:";
cin>> age;
cin.ignore();
console_reset ( h, w );
f ( age );
}
void shtuff()
{
HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );
WORD w;
CONSOLE_SCREEN_BUFFER_INFO c;
console_thingie ( h, w, c );
do_age ( h, w );
}
int main()
{
cout<<"Enter any age 0-??? at the prompt to get a response."<<endl;
cout<<"Try different numbers to get different responses."<<endl;
shtuff();
cout<<"See! Now enter a different number!"<< endl;
cout<<"0-34 is one response."<< endl;
cout<<"35-64 is another."<< endl;
cout<<"65-79 is another. Have fun!"<< endl;
cout<<"81-99 is another..."<< endl;
cout<<"100-200 is just crazy! And you can go beyond!"<< endl;
shtuff();
cout<<"See!? Thanks for using this proggy!"<< endl;
cout<<"Press enter to exit the program.";
cin.get();
}