can someone help me fix this?

Sep 12, 2012 at 6:22pm
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 Sep 12, 2012 at 6:27pm
Sep 12, 2012 at 6:47pm
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.
Sep 12, 2012 at 7:22pm
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 ^^
Sep 12, 2012 at 7:27pm
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" )
Sep 12, 2012 at 7:37pm
sorry, but it's still didn't work --"
Sep 12, 2012 at 7:44pm
I do not understand what means "did't work".
Last edited on Sep 12, 2012 at 7:45pm
Sep 13, 2012 at 3:55am
it's still can't debug, it's still error :(
Sep 13, 2012 at 1:05pm
@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.