Membuat Program Sederhana C++
Dalam pembahasan kali ini, saya akan membuat program sederhana dengan bahasa programan melalui Visual Studio C++.
Pembahasan kali ini saya membahas fungsi:
- Aritmatika
- If
- While
Dengan fungsi diatas saya akan membuat program untuk menghitung luas persegi, menghitung bonus gaji dan menghitung deret.
Berikut merupakan tampilan input dan output yang saya buat:
Dan berikut merupakan coding yang saya buat:
// ConsoleApplication4.cpp : Defines the entry point for the console application.
//
#include “stdafx.h”
#include <iostream>
using namespace std;
int main() {
int a;
cout << “Nama: E.M ALIF ASYHARI “;
cout << endl;
cout << “NPM: 1506715886”;
cout << endl;
cout << “KETIK 1 UNTUK MENGHITUNG LUAS PERSEGI”;
cout << endl;
cout << “KETIK 2 UNTUK MENGHITUNG BONUS GAJI”;
cout << endl;
cout << “KETIK 3 UNTUK MENGHITUNG DERET”;
cout << endl;
a = 0;
cin >> a;
switch (a) {
case 1:
cout << endl;
cout << “MENGHITUNG LUAS PERSEGI”;
cout << endl;
double s;
cout << “MASUKKAN SISI: “;
cin >> s;
cout << “HASIL LUAS PERSEGI: ” << s*s;
cout << endl;
break;
case 2:
{
cout << “MENGHITUNG BONUS GAJI”;
cout << endl;
int gaji = 0, x;
cout << “MASUKKAN GAJI: “;
cin >> x;
if (x >= 2000000) {
gaji = x / 10;
cout << “BONUS GAJI: ” << gaji;
cout << endl;
}
else cout << “ANDA TIDAK MENDAPATKAN BONUS GAJI”;
cout << endl;
break;
}
case 3:
{
int x, y, z;
cout << “MENGHITUNG DERET “;
cout << endl;
cout << “ANGKA PERTAMA: “;
cin >> x;
cout << “ANGKA AKHIR: “;
cin >> y;
cout << “MASUKKAN ANGKA YANG KELUAR: “;
cin >> z;
while (x > y) {
cout << x << “,”;
x -= z;
if (30 > x) { break; }
}
cout << “fire!”;
break;}
}
system(“PAUSE”);
return 0;
}
Sekian postingan tentang bahasa pemrograman melalui Visual C++, Terima Kasih