Thread: Howdy! Temperature prog

  1. #1
    Registered User [BIO]Asgard's Avatar
    Join Date
    Feb 2004
    Posts
    8

    Talking 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
    }

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Changing color is highly dependent on which compiler you are using.
    http://faq.cprogramming.com/cgi-bin/...&id=1043284392

  3. #3
    Registered User [BIO]Asgard's Avatar
    Join Date
    Feb 2004
    Posts
    8
    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

  4. #4
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,090
    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
    }

  5. #5
    Registered User [BIO]Asgard's Avatar
    Join Date
    Feb 2004
    Posts
    8
    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
    }
    Last edited by [BIO]Asgard; 02-26-2004 at 03:26 PM.

  6. #6
    Registered User [BIO]Asgard's Avatar
    Join Date
    Feb 2004
    Posts
    8
    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;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Temperature Conversion code problems
    By eroth88 in forum C Programming
    Replies: 6
    Last Post: 10-22-2006, 01:24 AM
  2. Temperature conversion...
    By Onslaught in forum C Programming
    Replies: 3
    Last Post: 10-21-2005, 01:15 PM
  3. Need help with a temperature c prog, thanks
    By McFury in forum C Programming
    Replies: 9
    Last Post: 05-26-2004, 01:14 AM
  4. read the CPU temperature
    By BianConiglio in forum Windows Programming
    Replies: 2
    Last Post: 05-19-2004, 11:41 AM
  5. functions ??? help
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 10-17-2001, 02:33 AM