Sep 18, 2012 at 2:18pm UTC
#include <iostream>
#include <conio.h>
#include <iomanip>
using namespace std;
void main()
{
float harga, TL, TB, KPE, KPA;
char jenis;
cout << "informasi tentang harga apartemen" << endl;
cout << "harga apartemen :";
cin >> harga;
cout << endl;
cout << "jenis apartemen :";
cin >> jenis;
cout << endl;
if (jenis == 'TL' )
{TL = harga - (harga*10/100);
cout << "besar pembayaran dengan jenis pembayaran tunai langsung :" << TL << endl;}
else if (jenis =='TB')
{TB =(harga / 10) - harga*5/100;
cout << "besar pembayaran dengan jenis pembayaran tunai bertahap :" << TB << "dibayar 10x selama 10bulan" << endl;}
else if (jenis =='KPE')
{KPE = (harga / 30);
cout << "besar pembayaran dengan jenis pembayaran kredit pendek :" << KPE << "dibayar 30x selama 30bulan" <<endl;}
else if (jenis =='KPA')
{KPA = (harga / 60)+ (harga*10/100);
cout << "besar pembayaran dengan jenis pembayaran kredit panjang :" << KPA << "dibayar 60x dengan bunga 10persen selama 60bulan" <<endl;}
else
{cout << "jenis kode salah" <<endl;}
getch();
}
when i debug it, and write TB it's say "jenis kode salah", help me someone
Last edited on Sep 18, 2012 at 2:18pm UTC
Sep 18, 2012 at 2:24pm UTC
This statement
if (jenis == 'TL' )
will always return false because jenis is declared as char and is capable to store only one char while you are trying to compare it with a character literal that consist from two characters.
Include header <string> and declare jenis as std::string jenis; and change character literals to string literals that is instead of for example 'TL' use "TL" (double quotes).
Sep 18, 2012 at 2:32pm UTC
thx it's fix my program, thank you so much ^^
Sep 18, 2012 at 2:35pm UTC
First of all please use code tags, the <> button on the right.
It is interesting you have float variables named float TL, TB, KPE, KPA;
. Then you have the comparison if (jenis == 'TL' )
If you meant to compare the variable jenis
and the variable TL
, then this is still invalid because jenis
is a char and TL
is a float.
It might automatically cast the jenis
into a float (because a char is just a small int), but I am guessing that won't do what you want.
Maybe TL, TB, KPE, KPA
should be strings, as Vlad was kind of saying.
Last edited on Sep 18, 2012 at 2:39pm UTC