将C代码转换为C# [英] Convert C code to C#

查看:93
本文介绍了将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();
}

推荐答案

我们不做你的功课:这是有原因的。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。



亲自尝试,你可能会发现它不是像你想的那么难!而我建议你做的就是编写自己的C#代码,而不是用不同的语言找到类似的东西,并希望这样做可以提交......你不会从中学到任何有用的东西。



如果您遇到特定问题,请询问相关问题,我们会尽力提供帮助。但是我们不会为你做这一切!
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!


它非常明确,你可以很容易地自己动手。从以下框架开始:

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





[更新]

请注意 (谢谢到 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代码,您可以看到它正在显示提示,从用户获取输入,然后根据输入执行一些计算。只是在你的家庭工作中做同样的事情,你会没事的。
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.


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆