c++ - 加法时如何使负数不计入(C++)
问题描述
我试着为功课制作一个这样的程序,但它没有用,有人可以帮我吗,我真的不知道该去哪里
#include <iostream>
using namespace std;
int main()
{
int a;
int b;
int c;
int d;
cout<<"enter 3 numbers"<<endl;
cin>>a;
cin>>b;
cin>>c;
d = a + b + c
if ( a <= 1 - = 0 )
cout<<d<<endl;
if ( b < 1 - = 0 )
cout<<d<<endl;
else ( c < 1 - = 0 )
return 0;
解决方案
您可能想尝试这样的事情:
int d = 0; // Initial value
if (a > 0)
{
d = d + a;
}
if (b > 0)
{
d = d + b;
}
if (c > 0)
{
d = d + c;
}
在上面的代码中,只有d
当它们是正数时,它们才会被添加到变量中。
推荐阅读
- linux - 如何使用 Bus、Device、Function 和 Offset 获取物理地址
- angular - 使用 adal angular 获取 azure AD 的刷新令牌
- spring-boot - 百里香模板引擎(布局:装饰)不会在 Spring Boot 中加载模板文件
- mysql - MySQL 每月限制 5 个
- c - 显示星号与使用函数显示字符
- html - 在导航栏中将 IMG 元素居中
- r - packrat R 永远安装软件包
- mediawiki-extensions - 如何将 Scribunto 版本与 Wikibase 容器版本匹配?
- ios - 如何在 MDCTabBar 中显示差异 viewContoller - swift
- unix - 仅从目录中查找最新的 hdfs 文件