#include<iostream.h>
#include<math.h>
#include<stdlib.h>
void index();
void index_38();
void yunsuan_38();
void jisuanye_38();
void jinzhi_38();
void pailieshu_38();
void x_38();
void jinzhi10_38();
void jinzhiq_38();
void pailie_38();
void zuhe_38();
void t_38();
void s_38();
void y_38();
void z_38();
void ss_38();
void fnNtoNUM();
double fn(){
double shu[100],jieguo=0.0;
char fuhao[100];
for(int i=0;;i++)//输入表达式,分别存入数【100】和
{
cin>>shu[i];
cin>>fuhao[i];
if(fuhao[i]=='=')break;
}
for(int j=0;j<=i;j++)//幂次方运算
{
if(fuhao[j]='^')
{
double f=1;
for(int ii=0;ii<shu[j+1];ii++)
f=f*shu[j];
shu[j+1]=f;
shu[j]=1;
fuhao[j]='*';
}
}
//乘除
for(j=0;j<=i;j++)
{
if(fuhao[j]=='*')
{
jieguo=shu[j]*shu[j+1];
shu[j+1]=jieguo;
shu[j]=0;
if(j>=1&&fuhao[j-1]=='-')fuhao[j]='-';
else fuhao[j]='+';
}
else if(fuhao[j]='/')
{
if(shu[j+1]==0)
{
cout<<"除数不能为0";
break;
}
else
{
jieguo=shu[j]/shu[j+1];
shu[j+1]=jieguo;
shu[j]=0;
if(j>=1&&fuhao[j-1]=='-')fuhao[j]='-';
else fuhao[j]='+';
}
}
}
//加减运算
for(int k=0;k<=i;k++)
{
if(fuhao[k]=='+')
{
jieguo=shu[k]+shu[k+1];
shu[k]=shu[k+1]=jieguo;
fuhao[k]='0';
}
else if(fuhao[k]=='-')
{
jieguo=shu[k]-shu[k+1];
shu[k]=shu[k+1]=jieguo;
fuhao[k]='0';
}
if(k==i)return jieguo;
}
}
void ss_38(){}
void t_38(){}
void s_38(){}
void y_38(){}
void z_38(){}
void jinzhiq_38(){}
void pailie_38(){}
void zuhe_38(){}
void fnNtoNUM(int n,int a[],int m,int c){
if(n<c){
a[m]=n;
return;
}
a[m]=n%c;
fnNtoNUM(n/c,a,++m,c);
}
void jinzhi10_38()
{
system("cls");
char shifou;
int n,m=0,a[16]={0},c;
cout<<"输入一个十进制整数(0-32767):";
cin>>n;
cout<<"请输入要转化为N进制:N=?"<<endl;
cin>>c;
for(int i=0;i<16;i++)
a[i]=c;
fnNtoNUM(n,a,m,c);
cout<<"对应的"<<c<<"进数是:";
for(n=15;n>=0;n--)
{
if(a[n]<c){
if(a[n]>9){
char x;
int t;
x='A';
t=a[n]-10;
x=x+t;
cout<<x;
}
else cout<<a[n];
}
}
cout<<"是否继续:是(Y),否:(y)";
cin>>shifou;
if(shifou=='Y'||shifou=='y')
{
jinzhi10_38();
}
else if(shifou='N'||shifou=='n')
{
system("cls");
jinzhi_38();
}
else
{
index_38();
}
void x_38()
{
system("cls");
int a;
cout<<endl;
cout<<endl;
cout<<endl;
cout<<" $$$$$$$$$选择要执行的运算$$$$$$$$$$$$"<<endl;
cout<<" $$ $$"<<endl;
cout<<" $$ 1.梯形面积运算 $$"<<endl;
cout<<" $$ $$"<<endl;
cout<<" $$ 2.三角形面积运算 $$"<<endl;
cout<<" $$ $$"<<endl;
cout<<" $$ 3.圆形面积运算 $$"<<endl;
cout<<" $$ $$"<<endl;
cout<<" $$ 4.长(正方)形面积运算 $$"<<endl;
cout<<" $$ $$"<<endl;
cout<<" $$ 5.扇形面积运算 $$"<<endl;
cout<<" $$ $$"<<endl;
cout<<" $$ 6.返回首页 $$"<<endl;
cout<<" $$ $$"<<endl;
cout<<" $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"<<endl;
cout<<" 亲输入您要的操作(1/2/3/4/5/6):";
cout<<"-----------输入数字选择你要计算的图形面积按任意键返回---------------"<<endl;
cin>>a;
system("cls");
switch(a){
case 1:
t_38();
break;
case 2:
s_38();
break;
case 3:
y_38();
break;
case 4:
z_38();
break;
case 5:
ss_38();
break;
case 6:
yunsuan_38();
break;
default:index_38();
}
}
void pailieshu_38()
{
system("cls");
int y;
cout<<endl;
cout<<endl;
cout<<endl;
cout<<" $$$$$$$$$选择要执行的运算$$$$$"<<endl;
cout<<" $$ m $$"<<endl;
cout<<" $$ 1.排列数P $$"<<endl;
cout<<" $$ n $$"<<endl;
cout<<" $$ $$"<<endl;
cout<<" $$ m $$"<<endl;
cout<<" $$ 2.组合数C $$"<<endl;
cout<<" $$ n $$"<<endl;
cout<<" $$ $$"<<endl;
cout<<" $$ 3.返回上一层 $$"<<endl;
cout<<" $$ $$"<<endl;
cout<<" $$ 4.返回首页 $$"<<endl;
cout<<" $$ $$"<<endl;
cout<<" $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"<<endl;
cout<<" 亲输入您要的操作(1/2/3/4):";
cin>>y;
if(y==1){
pailie_38();}
else if(y==2)
{
zuhe_38();}
else if(y==3){
yunsuan_38();}
else{
index_38();}
}
void jinzhi_38()
{
system("cls");
int y;
cout<<endl;
cout<<endl;
cout<<endl;
cout<<" $$$$$$$$$选择要执行的基本运算$$$$$"<<endl;
cout<<" $$ $$"<<endl;
cout<<" $$ 1.十进制转其他进制 $$"<<endl;
cout<<" $$ $$"<<endl;
cout<<" $$ 2.其他进制转十进制 $$"<<endl;
cout<<" $$ $$"<<endl;
cout<<" $$ 3.返回上一层 $$"<<endl;
cout<<" $$ $$"<<endl;
cout<<" $$ 4.返回首页 $$"<<endl;
cout<<" $$ $$"<<endl;
cout<<" $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"<<endl;
cout<<" 亲输入您要的操作(1/2/3/4):";
cin>>y;
if(y==1){
jinzhi10_38();}
else if(y==2)
{
jinzhiq_38();}
else if(y==3){
yunsuan_38();}
else{
index_38();
}
}
void jisuanye_38()
{
char shifou;
cout<<"请输入要运算的表达式,以等号结束"<<endl;
cout<<fn()<<endl;
cout<<"是否继续:是(Y),否:(y)";
cin>>shifou;
if(shifou=='Y'||shifou=='y')
{
jisuanye_38();
}
else if(shifou='N'||shifou=='n')
{
system("cls");
index_38();
}
}
void yunsuan_38()
{
system("cls");
int yunsuan;
cout<<endl;
cout<<endl;
cout<<" $$$$$$$$$选择要执行的基本运算$$$$$"<<endl;
cout<<" $$ $$"<<endl;
cout<<" $$ 1.基本运算 $$"<<endl;
cout<<" $$ $$"<<endl;
cout<<" $$ 2.进制转换 $$"<<endl;
cout<<" $$ $$"<<endl;
cout<<" $$ 3.排列组合 $$"<<endl;
cout<<" $$ $$"<<endl;
cout<<" $$ 4.常用公式 $$"<<endl;
cout<<" $$ $$"<<endl;
cout<<" $$ 5.返回首页 $$"<<endl;
cout<<" $$ $$"<<endl;
cout<<" $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"<<endl;
cout<<" 亲输入您要的操作(1/2/3/4/5):";
cin>>yunsuan;
switch(yunsuan){
case 1:
jisuanye_38();
break;
case 2:
jinzhi_38();
break;
case 3:
pailieshu_38();
break;
case 4:
x_38();
break;
case 5:
index_38();
break;
}
}
void index_38()
{
system("cls");
int xuanxiang;
cout<<endl;
cout<<endl;
cout<<" $$$$$$$$$$$$$$计算器$$$$$$$$$$$$$$"<<endl;
cout<<" $$ $$"<<endl;
cout<<" $$ 1.运算开始 $$"<<endl;
cout<<" $$ 2.使用说明 $$"<<endl;
cout<<" $$ 3.其他 $$"<<endl;
cout<<" $$ $$"<<endl;
cout<<" $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"<<endl;
cout<<" 亲输入您要的操作(1/2/3):";
cin>>xuanxiang;
if(xuanxiang==1)
{
yunsuan_38();
}
else if(xuanxiang==2)
{
cout<<"使用说明"<<endl;
}
else
{
cout<<"输入错误,请重新输入!";
index_38();
}
}
void main()
{
index_38();
}
C语言
局部函数定义是非法的
你把代码格式化一下
这个括号顶格
完整代码能发一下吗,你这应该是把函数定义在了别的函数里面,在C语言中这样定义是非法的
把第一行 iostream.h 的 .h 去掉
#include <iostream>
包含头文件后 加上
using namespace std;
main 函数 void 改成 int
int main()
double fn 的 for 循环 int i 拿到循环外边,j 也是
int i=0;
for(;;i++)
//...
int j=0;
for
void x_38() 前加个 大括号 }
}
void x_38()