-
Howdy! Temperature prog
Hi to all new here and new to C++ just making a temperature program that works by entering the temp and such ANY help is appreciated how would i go about making the background color change and the text any other suggestions or help is appreciated im a total newbie at this.
Code:
#include<iostream.h> //Allows Cin and Cout to be used
int main() //Allows starting of program
{
int temp;
cout <<"Please input the temperature\n\n:";
cin >>temp; //User input
if (temp>90)
{
cout <<"Spanish Weather : Wear shorts!\n"; //Prompt output based on user input
}
else if (temp>70)
{
cout <<"Ideal weather : Short sleaves are fine\n";
}
else if (temp>50)
{
cout <<"A little chilly : Wear a light jacket\n";
}
else if (temp>32)
{
cout <<"English weater : Wear a heavy coat\n";
}
else
{
cout <<"Stay inside\n";
}
return 0; //End the program
}
-
Changing color is highly dependent on which compiler you are using.
http://faq.cprogramming.com/cgi-bin/...&id=1043284392
-
Aha okay im using C++ 6.0 lol thats about all i know lol so help advice tips appreciated looking for friends here as well as answers! lol im rob and thanks for the link any other advice is cool as well :)
-
Hey rob, if you feel like it, you might want to update your program to use the new, standard headers. That means <iostream> instead of <iostream.h>. There are lots of places to find information on the difference between the two, but to put it simply, the old headers will start to not work with newer compilers. There is one extra change you must make to your program if you change to the new header. Here are three examples of how you can do it. I prefer the first, but some, especially beginners, prefer the second or third (also note I added some indentation in there just for fun):
Code:
#include<iostream> //Allows Cin and Cout to be used
int main() //Allows starting of program
{
int temp;
std::cout <<"Please input the temperature\n\n:";
std::cin >>temp; //User input
if (temp>90)
{
std::cout <<"Spanish Weather : Wear shorts!\n"; //Prompt output based on user input
}
else if (temp>70)
{
std::cout <<"Ideal weather : Short sleaves are fine\n";
}
else if (temp>50)
{
std::cout <<"A little chilly : Wear a light jacket\n";
}
else if (temp>32)
{
std::cout <<"English weater : Wear a heavy coat\n";
}
else
{
std::cout <<"Stay inside\n";
}
return 0; //End the program
}
Code:
#include<iostream> //Allows Cin and Cout to be used
using std::cout;
using std::cin;
int main() //Allows starting of program
{
int temp;
cout <<"Please input the temperature\n\n:";
cin >>temp; //User input
if (temp>90)
{
cout <<"Spanish Weather : Wear shorts!\n"; //Prompt output based on user input
}
else if (temp>70)
{
cout <<"Ideal weather : Short sleaves are fine\n";
}
else if (temp>50)
{
cout <<"A little chilly : Wear a light jacket\n";
}
else if (temp>32)
{
cout <<"English weater : Wear a heavy coat\n";
}
else
{
cout <<"Stay inside\n";
}
return 0; //End the program
}
Code:
#include<iostream> //Allows Cin and Cout to be used
using namespace std;
int main() //Allows starting of program
{
int temp;
cout <<"Please input the temperature\n\n:";
cin >>temp; //User input
if (temp>90)
{
cout <<"Spanish Weather : Wear shorts!\n"; //Prompt output based on user input
}
else if (temp>70)
{
cout <<"Ideal weather : Short sleaves are fine\n";
}
else if (temp>50)
{
cout <<"A little chilly : Wear a light jacket\n";
}
else if (temp>32)
{
cout <<"English weater : Wear a heavy coat\n";
}
else
{
cout <<"Stay inside\n";
}
return 0; //End the program
}
-
Easy there tiger lol i found the site but i dont know how to intergate the colours onto the program there must be a easier way?
Second thing is i am putting //What it does with the program any
//you can think of thta i have missed thats important let me know its my first proper program.
I like the indentation will put it in now :)
Oh p.s is there anyway to loop it back to the start if i enter in a invalid temp?
Code:
#include<iostream.h> //Allows Cin and Cout to be used
int main( void ) //Allows starting of program
{
int temp;
cout <<"Please input the temperature\n\n:";
cin >>temp; //User input
if (temp>110)
{
cout <<"Temperature error please re-enter\n\n\n";
}
else if (temp>=90 && temp<110)
{
cout <<"Spanish Weather : Wear shorts!\n"; //Prompt output based on user input
}
else if (temp>=70 && temp<90)
{
cout <<"Ideal weather : Short sleaves are fine\n";
}
else if (temp>50 && temp<70)
{
cout <<"A little chilly : Wear a light jacket\n";
}
else if (temp>32 && temp<50)
{
cout <<"English weater : Wear a heavy coat\n";
}
else if (temp>0 && temp<32)
{
cout <<"Stay inside\n";
}
else if (temp<0 && temp <10)
{
cout <<"Temperature below freezing wrap up warm\n";
}
else if (temp<11)
{
cout <<"Temperature Error please re-enter temperture\n";
}
return 0; //End the program
}
-
Right i have a color code how would i intergrate the two?
Code:
#include <stdio.h>
#include <windows.h>
int main ( void )
{
HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );
WORD wOldColorAttrs;
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
/*
* First save the current color information
*/
GetConsoleScreenBufferInfo(h, &csbiInfo);
wOldColorAttrs = csbiInfo.wAttributes;
/*
* Set the new color information
*/
SetConsoleTextAttribute ( h, FOREGROUND_RED | FOREGROUND_INTENSITY );
printf ( "This is a test\n" );
/*
* Restore the original colors
*/
SetConsoleTextAttribute ( h, wOldColorAttrs);
return 0;
}