Contoh soal:
Buatlah Program Aritmatika penjumlahan,pengurangan,pembagian,dan perkalian:
JUDUL:
Pergitungan Aritmatika
KAMUS:
Aritmatika ç char
variabelX ç integer
variabelY ç integer
hasil ç integer
DESKRIPSI:
Output <= kalkulator aritmatika
Output <= pilih perintah*, / , +, -
Input => aritmatika <=
character
Output <= variabelX
Input => pertama <=
integer
Output <= masukan angka kedua
Input =>variabelY <= integer
if (aritmatika == '*') then
{
output hasil=
variabelX * variabelY;
}
else if
(aritmatika == '/' )
{
output hasil= variabelX / variabelY
}
output else if (aritmatika == '+' )
{
hasil=
variabelX + variabelY
}
output else if (aritmatika == '-' )
{
hasil=
variabelX - variabelY;
}
else
{
output <<
" salah";
}
output << " = " << hasil
if (hasil %2==0)
{
output <<
" Genap ";
}
else
{
output <<
" Ganjil ";
}
//source code
//judul: perhitungan aritmatika
/*author: ariella risqy mauulana
25-sept-2022*/
#include <iostream>
using namespace std;
//kamus:
char aritmatika;
int variabelX;
int variabelY;
int hasil;
//deskripsi:
int main()
{
cout << "kalkulator aritmatika" << endl;
cout << "=====================" << endl;
cout << "pilihan perintah *,/,+,-:" ;
cin >> aritmatika ;
cout << "======================" << endl;
cout << "masukan variabel x: " ;
cin >> variabelX ;
cout << "masukan variabel y: " ;
cin >> variabelY ;
cout << "======================" << endl;
cout << variabelX << aritmatika << variabelY ;
if (aritmatika == '*')
{
hasil= variabelX * variabelY;
}
else if (aritmatika == '/')
{
hasil= variabelX / variabelY;
}
else if (aritmatika == '+')
{
hasil= variabelX + variabelY;
}
else if (aritmatika == '-')
{
hasil= variabelX - variabelY;
}
else
{
cout << "salah";
}
cout << " = " << hasil;
if (hasil %2==0)
{
cout << " genap " ;
}
else
{
cout << " ganjil " ;
}
}
//output
Komentar
Posting Komentar