DeVTeo
17-02-11, 04:41 AM
The Calculator in C++ is very easy but some peoples don't know How to apply green color in it.
#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.
#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.
#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
#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.
#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.
#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