Click here to Skip to main content
14,421,274 members
Rate this:
Please Sign up or sign in to vote.
See more:
Convert C to C#, the code to be converted is shown below:

What I have tried:

#include<stdio.h>
#include<conio.h>
main()
{
char h,l,g;
int a;
printf("Enter Heath e For Excellent And p For Poor ");
scanf("%c",&h);
printf("Enter Location c For City And v For Village ");
scanf("\n%c",&l);
printf("Enter Gender m For Male And f For Female ");
scanf("\n%c",&g);
printf("Enter Age ");
scanf("\n%d",&a);
if((h=='e')&&(l=='c')&&(g=='m')&&(a>=25||a<=35))
printf("\nThe Premium Is Rs.4 Per Thousand And His Policy Cannot Exceed Rs.2 Lakhs");
else if((h=='e')&&(l=='c')&&(g=='f')&&(a>=25||a<=35))
printf("\nThe Premium Is Rs.3 Per Thousand And Her Policy Cannot Exceed Rs.1 Lakhs");
else if((h=='p')&&(l=='v')&&(g=='m')&&(a>=25||a<=35))
printf("\nThe Premium Is Rs.6 Per Thousand And Cannot Exceed Rs. 10,000");
else
printf("\n not Insured");
getch();
}
Posted
Updated 27-Nov-18 8:45am
v2
Comments
Richard MacCutchan 27-Nov-18 9:26am
   
What you have tried is not C#.
Rate this:
Please Sign up or sign in to vote.

Solution 1

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think! And what I'd suggest you do is write your own C# code, instead of finding something similar in a different language and hoping that'll do to hand in ... you won't learn anything useful from doing that.

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

It is pretty strightforward, you may easily 'do it yourself'. Start from the following skeleton:
public static void Main()
 {
   char h;
   Console.Write("Enter Heath e For Excellent And p For Poor ");
   h = Convert.ToChar(Console.Read());
   // dummy variable initialization, just for making the code compile, write the actual code to set values
   int a = 27; char l = 'c', g = 'm';
   if ((h == 'e') && (l == 'c') && (g == 'm') && (a >= 25 || a <= 35))
     Console.WriteLine("\nThe Premium Is Rs.4 Per Thousand And His Policy Cannot Exceed Rs.2 Lakhs");
   // continue here...
 }


[update]
Please note (thanks to Richard for pointing out), you original
Quote:
(a>=25||a<=35)
and my 'translated' (identical) one, both make no sense.
Those should be instead
(a>=25 && a<=35)

[/update]
   
v2
Comments
Richard MacCutchan 27-Nov-18 9:28am
   
(a >= 25 || a <= 35) ??
Richard Deeming 27-Nov-18 11:07am
   
The rude and lazy OP only demanded a conversion, not a fix. :)
Richard MacCutchan 27-Nov-18 11:09am
   
lol :)
CPallini 27-Nov-18 17:43pm
   
Indeed! :-D
CPallini 27-Nov-18 18:19pm
   
Good catch. Thank you.
Rate this:
Please Sign up or sign in to vote.

Solution 3

If you read the c code you can see that it is displaying a prompt, getting input from the user and then performing some calculations based on the input. Just do the same in your home work and you will be fine.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100