c++的问题,各位帮我看看是什么地方有问题!!谢谢!!我查过很多次了!!!查不出来!!

来源:百度知道 编辑:UC知道 时间:2024/05/21 12:13:15
#include <stdio.h>
main()
{
int value, chioce;

printf("convert :\n");
printf(" 1: decimal to hexadecimal\n");
printf(" 2: hexadecimal to decimal\n");
printf(" 3: decimal to octal\n");
printf(" 4: octal to decimal\n");
printf(" 5: octal to hexaddecimal\n");
printf(" 6: hexadecimal to octal\n");

printf("enter your choice: ");
scanf("%d", &choice);

if(choice==1)
{
printf("enter a decimal value: ");
scanf("%d",&value);
printf("%d in hexadecimal is %x\n", value,value);
}
else if(choice==2)
{
printf("enter a hexadecimal value: ");
scanf("%x", &value);
printf("%x in decimal is %d\n", value,value);
}
else is (choice==3

大多数错误是粗心打错的 楼主要细心了
main() 要加 void

int value, chioce;
但在else is (choice==3)等几句里
是choice
else is 改成 else if

错误的地方在代码中用 *********** 注释了

下面是正确的代码
#include <stdio.h>
void main()//**************
{
int value, chioce;

printf("convert :\n");
printf(" 1: decimal to hexadecimal\n");
printf(" 2: hexadecimal to decimal\n");
printf(" 3: decimal to octal\n");
printf(" 4: octal to decimal\n");
printf(" 5: octal to hexaddecimal\n");
printf(" 6: hexadecimal to octal\n");

printf("enter your choice: ");
scanf("%d", &chioce);

if(chioce==1)
{
printf("enter a decimal value: ");
scanf("%d",&value);
printf("%d in hexadecimal is %x\n", value,value);