Likes: 0
Results 1 to 1 of 1
Thread: [C++]Calculator + green color
-
17-02-11, 04:41 AM #1
[C++]Calculator + green color
Register to remove this adThe 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; }
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; }
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; }
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
› See More: [C++]Calculator + green colorLast edited by DeVTeo; 17-02-11 at 04:53 AM.