1个回答
2013-11-25
展开全部
(1)
#include<iostream>
using namespace std;
int main()
{
float num1,num2;
char ch;
begin:
cout<<"请输入第1个数:\n";
cin>>num1;
cout<<"请输入运算符:\n";
cin>>ch;
cout<<"请输入第2个数:\n";
cin>>num2;
switch(ch)
{
case '+':
cout<<"结果:"<<num1+num2<<endl;
break;
case '-':
cout<<"结果:"<<num1-num2<<endl;
break;
case '*':
cout<<"结果:"<<num1*num2<<endl;
break;
case '/':
if(int(num2)!=0)
{
cout<<"结果:"<<num1/num2<<endl;
}
else
{
cout<<"除数不能为0,请重新输入.\n";
goto begin;
}
break;
default:
cout<<"你输入的运算符错误,请重新输入.\n";
goto begin;
}
getchar();
return 0;
}
(2)
#include <iostream>
#include<string>
using namespace std;
int main()
{
char num1[50];
char num2[50];
char ch;
int n=0;
int i=0;
float count=0;
string inStr;
begin:
cout<<"请输入:";
cin>>inStr;
memset(num1,0,50);
memset(num2,0,50);
for(i=0; inStr[i]!='\0'; i++)
{
if(inStr[i]=='+' ||inStr[i]=='-' ||inStr[i]=='*' ||inStr[i]=='/' )
{
break;
}
else
{
num1[i]=inStr[i];
}
}
ch=inStr[i];
i++;
for(; inStr[i]!='\0'; i++)
{
if(inStr[i]=='+' ||inStr[i]=='-' ||inStr[i]=='*' ||inStr[i]=='/' )
{
break;
}
else
{
num2[n]=inStr[i];
n++;
}
}
switch(ch)
{
case '+':
count=float(atoi(num1))+float(atoi(num2));
break;
case '-':
count=float(atoi(num1))-float(atoi(num2));
break;
case '*':
count=float(atoi(num1))*float(atoi(num2));
break;
case '/':
if(atoi(num2)!=0)
{
count=float(atoi(num1))/float(atoi(num2));
}
else
{
cout<<"除数不能为0"<<endl;
goto begin;
}
break;
}
cout<<"结果是:"<<count<<endl;
}
#include<iostream>
using namespace std;
int main()
{
float num1,num2;
char ch;
begin:
cout<<"请输入第1个数:\n";
cin>>num1;
cout<<"请输入运算符:\n";
cin>>ch;
cout<<"请输入第2个数:\n";
cin>>num2;
switch(ch)
{
case '+':
cout<<"结果:"<<num1+num2<<endl;
break;
case '-':
cout<<"结果:"<<num1-num2<<endl;
break;
case '*':
cout<<"结果:"<<num1*num2<<endl;
break;
case '/':
if(int(num2)!=0)
{
cout<<"结果:"<<num1/num2<<endl;
}
else
{
cout<<"除数不能为0,请重新输入.\n";
goto begin;
}
break;
default:
cout<<"你输入的运算符错误,请重新输入.\n";
goto begin;
}
getchar();
return 0;
}
(2)
#include <iostream>
#include<string>
using namespace std;
int main()
{
char num1[50];
char num2[50];
char ch;
int n=0;
int i=0;
float count=0;
string inStr;
begin:
cout<<"请输入:";
cin>>inStr;
memset(num1,0,50);
memset(num2,0,50);
for(i=0; inStr[i]!='\0'; i++)
{
if(inStr[i]=='+' ||inStr[i]=='-' ||inStr[i]=='*' ||inStr[i]=='/' )
{
break;
}
else
{
num1[i]=inStr[i];
}
}
ch=inStr[i];
i++;
for(; inStr[i]!='\0'; i++)
{
if(inStr[i]=='+' ||inStr[i]=='-' ||inStr[i]=='*' ||inStr[i]=='/' )
{
break;
}
else
{
num2[n]=inStr[i];
n++;
}
}
switch(ch)
{
case '+':
count=float(atoi(num1))+float(atoi(num2));
break;
case '-':
count=float(atoi(num1))-float(atoi(num2));
break;
case '*':
count=float(atoi(num1))*float(atoi(num2));
break;
case '/':
if(atoi(num2)!=0)
{
count=float(atoi(num1))/float(atoi(num2));
}
else
{
cout<<"除数不能为0"<<endl;
goto begin;
}
break;
}
cout<<"结果是:"<<count<<endl;
}
网易云信
2023-12-06 广告
2023-12-06 广告
UIkit是一套轻量级、模块化且易于使用的开源UI组件库,由YOOtheme团队开发。它提供了丰富的界面元素,包括按钮、表单、表格、对话框、滑块、下拉菜单、选项卡等等,适用于各种类型的网站和应用程序。UIkit还支持响应式设计,可以根据不同...
点击进入详情页
本回答由网易云信提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询