繁体   English   中英

If(输入值==数字)

[英]If(value of input==number)

我是C ++的初学者,我尝试创建一个小程序,我对if(输入值== x)else有一点问题...

有人可以帮我吗?

Int main () {...  int choice;
    do{
    cout <<"choose from the list below to make the convertion"<<endl;
    cout <<"1 : € to $, 2 :$ to €,3 :$ to £,4: £ to$\n";
    cin >>choice;

           if (choice =='1') {cout << "Pls enter € value to convert to $."<<endl;

           cin >>value;

            cout <<"euro\t\t to\t\t dollard\n"; cout <<value<<"\t\t\t\t"<<value*diff<<endl; } 

           else if (choice=='2'){.....

这里的问题是您正在将一个int变量(选择)与一个字符文字(“ 1”)进行比较。 与“ 1”进行比较时,实际上是与字符“ 1”的ASCII值进行比较,即49。

因此,要解决您的问题,请更换

if (choice =='1') 

if (choice ==1) 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM