Follow us on
Follow us on Facebook Follow us on Twitter Watch us on YouTube


MMOCoin

Results 1 to 1 of 1
  1. #1
    Beginner
    DeVTeo's Avatar
    Join Date
    Nov 2010
    Location
    Bulgaria
    Posts
    9
    Rep Power
    16
    Reputation
    1

    [C++]Calculator + green color


    Register to remove this ad
    The Calculator in C++ is very easy but some peoples don't know How to apply green color in it.
    Code:
    #include <iostream>
    using namespace std;
    int main()
    {
        int a,b;
        char ch;
        cout<<"+ | - | * | / |"<<endl;
        cin>>ch;
        
        if(ch=='+')
        {
                   cout<<"Type a number:  "<<endl;
                   cin>>a;
                   
                   cout<<"Type another number:  "<<endl;
                   cin>>b;
                   cout<<a+b<<endl;
        }
        
        if(ch=='-')
        {
                   cout<<"Type a number:  "<<endl;
                   cin>>a;
                   
                   cout<<"Type another number:  "<<endl;
                   cin>>b;
                   cout<<a-b<<endl;
        }
        
        if(ch=='*')
        {
                   cout<<"Type a number:  "<<endl;
                   cin>>a;
                   
                   cout<<"Type another number:  "<<endl;
                   cin>>b;
                   cout<<a*b<<endl;
        }
        
        if(ch=='/')
        {
                   cout<<"Type a number:  "<<endl;
                   cin>>a;
                   
                   cout<<"Type another number:  "<<endl;
                   cin>>b;
                   cout<<a/b<<endl;
        }
        cin.get();
        system("pause");
        return 0;
    }
    This is code of the calculator.
    Code:
    #include <iostream>
    #include <windows.h>
    
    using namespace std;
    
    HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE) ;
    int main()
    {
        WORD color = FOREGROUND_GREEN;
        SetConsoleTextAttribute(hout, color) ;
        cout << "This is colored text!" ;
    
        cin.get() ;
        return 0;
    }
    This is code of green color.

    Code:
    #include <iostream>
    #include <windows.h>
    using namespace std;
    HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);
    int main()
    {
        WORD color=FOREGROUND_GREEN;
        SetConsoleTextAttribute(hout,color);
        int a,b;
        char ch;
        cout<<"+ | - | * | / |"<<endl;
        cin>>ch;
        
        if(ch=='+')
        {
                   cout<<"Type a number:  "<<endl;
                   cin>>a;
                   
                   cout<<"Type another number:  "<<endl;
                   cin>>b;
                   cout<<a+b<<endl;
        }
        
        if(ch=='-')
        {
                   cout<<"Type a number:  "<<endl;
                   cin>>a;
                   
                   cout<<"Type another number:  "<<endl;
                   cin>>b;
                   cout<<a-b<<endl;
        }
        
        if(ch=='*')
        {
                   cout<<"Type a number:  "<<endl;
                   cin>>a;
                   
                   cout<<"Type another number:  "<<endl;
                   cin>>b;
                   cout<<a*b<<endl;
        }
        
        if(ch=='/')
        {
                   cout<<"Type a number:  "<<endl;
                   cin>>a;
                   
                   cout<<"Type another number:  "<<endl;
                   cin>>b;
                   cout<<a/b<<endl;
        }
        cin.get();
        system("pause");
        return 0;
    }
    This is Calculator + Green Color.

    Text color:
    FOREGROUND_GREEN - green color
    FOREGROUND_BLUE - blue color
    FOREGROUND_INTENSITY - white color


    Background color:

    BACKGROUND_GREEN - green color
    BACKGROUND_BLUE - blue color
    BACKGROUND_INTENSITY - white color
    Last edited by DeVTeo; 17-02-11 at 04:53 AM.

 

 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -5. The time now is 07:42 PM.
Powered by vBulletin® Copyright ©2000-2026, Jelsoft Enterprises Ltd.
vBulletin Licensed to: MMOPro.org
vBulletin Skin By: PurevB.com