请问如何让修改下次C++程序?

来源:百度知道 编辑:UC知道 时间:2024/06/24 10:27:42
#include<stdio.h>
#include<math.h>
void main()
{
float x,y;
printf("please input the number:");
scanf("%f",&x);
if((x>=0)&&(x<10))
y=sin(x);
else if(x<20)
y=cos(x);
else if(x<30)
y=exp(x)-1;
else if(x<40)
y=log(x+1);
printf("%f",y);
else
printf("未定义",y);
}
我想让输入没有定义的数值时候输出未定义,而有定义的数值输出我自己的定义函数值,请问上面应该怎么改??提示一直有错误!!
ompiling...
Error spawning cl.exe

Cpp1.obj - 1 error(s), 0 warning(s)
下面仁兄的出现这个问题!!!!

#include<iostream>//这个是C++的标准头文件
#include<stdio.h>
#include<math.h>
using namespace std;
void main()
{
float x,y;
int i;
printf("please input the number:");
scanf("%f",&x);
i=(int)x/10;
switch(i)
{
case 1 :y=sin(x);cout<<"y"<<endl; break;
case 2 :y=cos(x);cout<<"y"<<endl; break;
case 3 :y=exp(x)-1;cout<<"y"<<endl; break;
case 4 :y=log(x+1); cout<<"y"<<endl; break;
default: cout<<"未定义"<<endl;

}
}

你的程序整个写的是C的结构和语句.
你把该成这样还不行的话,就把头文件的".h"去掉,再试试