否则if语句不能正常工作C ++ [英] Else if statement not working C++

查看:73
本文介绍了否则if语句不能正常工作C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新编码我不明白为什么if语句显示if语句的输出尽管没有错误。如果声明在每天的特定时间拨打电话时应扣除%50,并在电话呼叫超过60时扣除额外的%15。第二声明应该只取%50,因为条件为真,之后会有太多其他更改如果输出显示低于60的折扣。



非常感谢你。



I'm new coding I don't understand why else if statement displays the output from if statement despite of not error. If statement should deduct a %50 when phone call is at specific time a day and deduct an extra %15 off when phone call is over 60. Second statement should take only %50 off because the condition is true, after way too many changes else if output displays both discount despite of being lower than 60.

Thanks you so much.

    cout << "Enter start time: ";
    cin >> startcall;
    cout << "Enter length of call in minutes: ";
    cin >>  duration;
    
    if (duration > 60 || startcall >=1800 || startcall < 800) {
       discount = (duration * rate /2)*0.15;
       grosscost = ((((duration * rate/2)-discount)) * 0.40) + (((duration * rate/2)-discount));
       netcost = grosscost;
        
    }else if(duration <60 || startcall >=1800 ||startcall <800){
        grosscost = ((duration *rate /2)*0.40) + (duration *rate/2);
        netcost = grosscost;
    }
    
    cout <<"Gross Cost: $ " <<grosscost <<endl;
    cout <<"Net cost: $ " <<netcost <<endl;
    

    return 0;

}





我的尝试:



我试图更改变量的名称,我检查了大括号的顺序。我多次在纸上写下了这个操作。我检查了编程书籍,他们给我举例说明了函数是如何工作的,但我想我需要一个例子来理解我做错了什么。



谢谢



What I have tried:

I tried to change the variable's names, I checked the curly bracket order. I wrote down the operation on paper several times. I checked programing books, they give me examples of how functions work, but I think I need an example to understand what I'm doing wrong.

thanks

推荐答案

<< grosscost<< endl;
cout<< 净费用:
" <<grosscost <<endl; cout <<"Net cost:


<< netcost<< endl;


return 0 ;

}
" <<netcost <<endl; return 0; }





我的尝试:



我试过更改变量的名称,我检查了大括号的顺序。我在纸上写下了几次操作。我查了编程书,他们给我一些函数如何工作的例子,但我想我需要一个例子来理解我在做什么错误。



谢谢



What I have tried:

I tried to change the variable's names, I checked the curly bracket order. I wrote down the operation on paper several times. I checked programing books, they give me examples of how functions work, but I think I need an example to understand what I'm doing wrong.

thanks


你编写的方式声明是错的。

你可能意味着(请注意你可以有利地重构这样的代码)

The way you have written the if statements is wrong.
You probably meant (please note you may profitably refactor such a code)
if (duration > 60 && (startcall >=1800 || startcall < 800) )
{
  discount = (duration * rate /2)*0.15;
  grosscost = ((((duration * rate/2)-discount)) * 0.40) + (((duration * rate/2)-discount));
  netcost = grosscost;

}
else if(duration < 60 && ( startcall >=1800 ||startcall <800) )
{
  grosscost = ((duration *rate /2)*0.40) + (duration *rate/2);
  netcost = grosscost;
}



但这只是猜测,因为你没有提供足够的细节。


However it is just a guess, because you didn't provide enough details.


这篇关于否则if语句不能正常工作C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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