嵌套开关的问题 [英] problem with nested switches

查看:69
本文介绍了嵌套开关的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


当我编译它时,我在第16行得到一个错误,其中包含c的情况。


#include< cstdlib>

#include< iostream>

#include< math.h>

using namespace std;


int main()

{

浮动x,y;

双r;

char o;


cout<<"要使用计算器,请按C" << endl<<"要按下Q"

<< endl;


switch(o);

{

case''c'':cout<<"输入数学运算 << endl;

cin>> x>> o>> y;


switch(o)

{

case''+'':r = x + y;

cout<<"""""" << r<< endl;

休息;


case'' - '':r = xy;

cout<<"结果是:" << r<< endl;

休息;


case''*'':r = x * y;

cout<<"结果是:" << r<< endl;

休息;


case''/'':r = x / y;

cout<<"结果是:" << r<< endl;

休息;


case''^'':r = pow(x,y);

cout<<"结果是:" <<<<< endl;

休息;


默认:cout<<"错误:输入错误"

<< endl;

}

休息;


案例''q'':cout <<" CYA" << endl;

休息;

}


system(" PAUSE");

返回EXIT_SUCCESS;

}

伙计们,我刚开始编程2天前所以请放轻松我:)。


-

Mustafa Zaza

Hello,

When I compile it I get an error in line 16, which got case ''c''.

#include <cstdlib>
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
float x, y;
double r;
char o;

cout <<"To use the calculator press C" <<endl <<"To quite press Q"
<<endl;

switch (o);
{
case ''c'': cout <<"Enter the mathmatical operation" <<endl;
cin >>x >>o >>y;

switch (o)
{
case ''+'': r=x+y;
cout <<"The result is: " <<r <<endl;
break;

case ''-'': r=x-y;
cout <<"The result is: " <<r <<endl;
break;

case ''*'': r=x*y;
cout <<"The result is: " <<r <<endl;
break;

case ''/'': r=x/y;
cout <<"The result is: " <<r <<endl;
break;

case ''^'': r=pow(x, y);
cout <<"The result is: " <<r <<endl;
break;

default: cout <<"Error: wrong input"
<<endl;
}
break;

case ''q'': cout <<"cya" <<endl;
break;
}

system("PAUSE");
return EXIT_SUCCESS;
}
Guys, I just started programming 2 days ago so take it easy on me :).

--
Mustafa Zaza

推荐答案

MZaza写道:
MZaza wrote:

您好,


当我编译它时,我在第16行得到一个错误,其中包含c的情况。


#include< cstdlib>

#include< iostream>

#include< math.h>

using namespace std;


int main()

{

浮动x,y;

双r;

char o;


cout<<"要使用计算器,请按C" << endl<<"要完全按下Q"

<< endl;


switch(o);
Hello,

When I compile it I get an error in line 16, which got case ''c''.

#include <cstdlib>
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
float x, y;
double r;
char o;

cout <<"To use the calculator press C" <<endl <<"To quite press Q"
<<endl;

switch (o);



分号?这里''o'的价值是多少?

A semicolon? And what is the value of ''o'' here?


{

case''c'':cout<< 输入数学运算 << endl;

cin>> x>> o>> y;


switch(o)

{

case''+'':r = x + y;

cout<<"""""" << r<< endl;

休息;


case'' - '':r = xy;

cout<<"结果是:" << r<< endl;

休息;


case''*'':r = x * y;

cout<<"结果是:" << r<< endl;

休息;


case''/'':r = x / y;

cout<<"结果是:" << r<< endl;

休息;


case''^'':r = pow(x,y);

cout<<"结果是:" <<<<< endl;

休息;


默认:cout<<"错误:输入错误"

<< endl;

}

休息;


案例''q'':cout <<" CYA" << endl;

休息;

}


system(" PAUSE");

返回EXIT_SUCCESS;

}


伙计们,我刚开始编程2天前所以请放轻松我:)。
{
case ''c'': cout <<"Enter the mathmatical operation" <<endl;
cin >>x >>o >>y;

switch (o)
{
case ''+'': r=x+y;
cout <<"The result is: " <<r <<endl;
break;

case ''-'': r=x-y;
cout <<"The result is: " <<r <<endl;
break;

case ''*'': r=x*y;
cout <<"The result is: " <<r <<endl;
break;

case ''/'': r=x/y;
cout <<"The result is: " <<r <<endl;
break;

case ''^'': r=pow(x, y);
cout <<"The result is: " <<r <<endl;
break;

default: cout <<"Error: wrong input"
<<endl;
}
break;

case ''q'': cout <<"cya" <<endl;
break;
}

system("PAUSE");
return EXIT_SUCCESS;
}
Guys, I just started programming 2 days ago so take it easy on me :).



-

请在通过电子邮件回复时删除资金''A'

我不要回复最热门的回复,请不要问

--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


MZaza schrieb:
MZaza schrieb:

你好,


当我编译它时,我在第16行得到一个错误,它得到了'c'的情况。
Hello,

When I compile it I get an error in line 16, which got case ''c''.



如果您向我们提供了您收到的错误消息,将会有所帮助。

It would help if you provided us the error message you got.


#include< cstdlib> ;

#include< iostream>

#include< math.h>

using namespace std;


int main()

{

浮动x,y;

双r;

char o;


cout<<"要使用计算器,请按C" << endl<<"要完全按下Q"

<< endl;


switch(o);
#include <cstdlib>
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
float x, y;
double r;
char o;

cout <<"To use the calculator press C" <<endl <<"To quite press Q"
<<endl;

switch (o);



^

尝试删除分号。

^
Try to remove the semicolon here.


{

case''c'':cout<<"输入数学运算 << endl;

cin>> x>> o>> y;
{
case ''c'': cout <<"Enter the mathmatical operation" <<endl;
cin >>x >>o >>y;



[...]


-

Thomas
http://www.netmeister.org/news/learn2quote.html

sigfault

[...]

--
Thomas
http://www.netmeister.org/news/learn2quote.html
sigfault


3月5日,9:13 pm,Victor Bazarov < v.Abaza ... @ comAcast.netwrote:
On Mar 5, 9:13 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:

MZaza写道:
MZaza wrote:

您好,
Hello,


当我编译它时,我在第16行得到一个错误,得到了'c'的情况。
When I compile it I get an error in line 16, which got case ''c''.


#include< cstdlib>

#include< iostream>

#include < math.h>

using namespace std;
#include <cstdlib>
#include <iostream>
#include <math.h>
using namespace std;


int main()

{

浮动x,y;

double r;

char o;
int main()
{
float x, y;
double r;
char o;


cout<<"要使用计算器,请按C" << endl<<""要按Q"

<< endl;
cout <<"To use the calculator press C" <<endl <<"To quite press Q"
<<endl;


switch(o);
switch (o);



分号?这里''o'的价值是多少?


A semicolon? And what is the value of ''o'' here?


{

case''c'':cout<< 输入数学运算 << endl;

cin>> x>> o>> y;
{
case ''c'': cout <<"Enter the mathmatical operation" <<endl;
cin >>x >>o >>y;


switch(o)

{

case''+'':r = x + y;

cout<<"结果是:" << r<< endl;

休息;
switch (o)
{
case ''+'': r=x+y;
cout <<"The result is: " <<r <<endl;
break;


case'' - '':r = xy;

cout<<"结果是: " << r<< endl;

休息;
case ''-'': r=x-y;
cout <<"The result is: " <<r <<endl;
break;


case''*'':r = x * y;

cout<<"结果是: << r<< endl;

休息;
case ''*'': r=x*y;
cout <<"The result is: " <<r <<endl;
break;


case''/'':r = x / y;

cout<<"结果是: << r<< endl;

休息;
case ''/'': r=x/y;
cout <<"The result is: " <<r <<endl;
break;


case''^'':r = pow(x,y);

cout<<" ;结果是: << r<< endl;

休息;
case ''^'': r=pow(x, y);
cout <<"The result is: " <<r <<endl;
break;


default:cout<<"错误:输入错误"

<< endl;

}

休息;
default: cout <<"Error: wrong input"
<<endl;
}
break;


case''q'':cout<<" cya" << endl;

休息;

}
case ''q'': cout <<"cya" <<endl;
break;
}


system(" PAUSE" ;);

返回EXIT_SUCCESS;

}
system("PAUSE");
return EXIT_SUCCESS;
}


伙计们,我刚刚开始编程2几天前所以放轻松对我:)。
Guys, I just started programming 2 days ago so take it easy on me :).



-

请在通过电子邮件回复时删除资金''A'

我不要回复最热门的回复,请不要问


--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask



我应该从用户那里得到o的值,就像x和

y。

这就是你的意思吗?

I should get the value of the ''o'' from the user, just as the x and the
y.
Is that what you mean?


这篇关于嵌套开关的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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