本文介绍了将C代码转换为C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将C转换为C#,要转换的代码如下所示:



我尝试过:



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();
}

推荐答案


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...
 }





[更新]

请注意 (谢谢到 Richard 指出),你原来的



[update]
Please note (thanks to Richard for pointing out), you original

Quote:

(a> = 25 || a< = 35)

(a>=25||a<=35)

和我的'翻译'(相同),没有意义

那些应该是

and my 'translated' (identical) one, both make no sense.
Those should be instead

(a>=25 && a<=35)



[/ update]


[/update]



这篇关于将C代码转换为C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 16:46