can someone help me fix this?

i have an assignment to read these types of fields, the value of a land mortgage and then calculate the cost of insurance and displays the results. Use an enumerated data type for this kind of field.

#include <iostream>
#include <conio.h>
#include <iomanip>

using namespace std;

void main ()
{
const int tanggungan = 50000;
char ladang;
float luas;
float biaya;

cout << " Biaya Asuransi ladang " << endl;
cout << " Jenis ladang : ";
cin >> ladang;
cout << endl;
cout << " Luas tanah : " ;
cin >> luas;
cout << endl;
if ( ladang == 'kedelai' )
{cout << " Asuransi ladang " << ladang << " adalah Rp " << (7/200*tanggungan)*luas*2 << endl;}
else if (ladang=='kentang')
{cout << " Asuransi ladang " << ladang << " adalah Rp " << (7/200*tanggungan)*luas*2 << endl;}
else if (ladang=='bawang')
{cout << " Asuransi ladang " << ladang << " adalah Rp " << (7/200*tanggungan)*luas*2 << endl;}
else if (ladang=='cabai')
{cout << " Asuransi ladang " << ladang << " adalah Rp " << (7/200*tanggungan)*luas*2 << endl;}
else if (ladang=='padi')
{cout << " Asuransi ladang " << ladang << " adalah Rp " << (7/200*tanggungan)*luas*1.5 << endl;}
else if (ladang=='jagung')
{cout << " Asuransi ladang " << ladang << " adalah Rp " << (7/200*tanggungan)*luas*1.5 << endl;}
else
{cout << " Asuransi ladang " << ladang << " adalah Rp " << (7/200*tanggungan)*luas << endl;}

getch ();
}

when i debug it, it's always says "too many characters in constant"
can someone help me fix this?
Last edited on
Variable ladang is declared as
char ladang;

That means that in can contain only one character.

Here

ladang == 'kedelai'

you are tryaing compare one character (ladang) with multicharacter literal 'kedelai'. So there is no any sense in this comparision.

As for the error message then it means that your character literals are too long and exceed size of int.
so what must i do to make this can work?
i really don't get it, sorry because i'm still new at learning c++ in university ^^
Include header <string>. Instead of declaration

char ladang;

write

std::string ladang;

In all if statements change character literals to string literals that is use double quotes as fro example

if ( ladang == "kedelai" )
sorry, but it's still didn't work --"
I do not understand what means "did't work".
Last edited on
it's still can't debug, it's still error :(
@marvin77

Please re-post the code with the changes you made. Can't help what we can't see.
Topic archived. No new replies allowed.