Kamis, 27 Desember 2018

MEMBUAT OPERATOR RELASI C++

PERTEMUAN 3 TASK 1

Pada postingan kali ini saya menggunakan setcolor untuk mengubah warna tulisan, supaya menjadi lebih menarik.
Untuk mengubah warna tulisannya harus menggunakan header iostream dan windows.h dan menggunakan:
void setcolor(unsigned short color)
{
HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);
   SetConsoleTextAttribute(hCon,color);
}

kode warna:
0 = Black
1 = Blue
2 = Green
3 = Aqua
4 = Red
5 = Purple
6 = Yellow
7 = White
8 = Gray
9 = Light Blue



Langsung aja pada kodingannya.

#include <iostream>
#include <windows.h>

void setcolor(unsigned short color)
{
HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);
   SetConsoleTextAttribute(hCon,color);
}
int main()
{

     float a, b, c, d, e, f, X, Y;
     setcolor(12);
     cout<<"#################OPERASI RELASI C++####################"<<endl;

     cout<<"Masukan Nilai X = "; cin>>X;
     cout<<"Masukan Nilai Y = "; cin>>Y;
     cout<<"#######################################################"<<endl;
     a = X < Y;
     b = X > Y;
     c = X != Y;
     d = X <= Y;
     e = X >= Y;
     f = X == Y;
     cout<<endl;

     cout<<"\nHasil dari "<<X<<" < "<<Y<<"  = "<<a;
     cout<<"\nHasil dari "<<X<<" > "<<Y<<"  = "<<b;
     cout<<"\nHasil dari "<<X<<" != "<<Y<<" = "<<c;
     cout<<"\nHasil dari "<<X<<" <= "<<Y<<" = "<<d;
     cout<<"\nHasil dari "<<X<<" >= "<<Y<<" = "<<e;
     cout<<"\nHasil dari "<<X<<" == "<<Y<<" = "<<f<<endl;

     system("pause");
     return 0;
}


Tidak ada komentar:

Posting Komentar