C 如何基于另一个变量和某些算术定义变量的值
C++ How to define the value of a variable based on another variable and some arithmetic
我是C 的新手,并且通常是编程。在我的程序中,我试图通过向用户索取地球重量,然后他们想要将地球重量进行比较的行星来计算其他行星上的物体的重量。我希望使用Switch(PlanetNumber),希望根据他们选择的数字(1-6),该程序将根据所选情况定义可变的'''。我遇到了一个错误:"分配权重 * 0.78 = etheraweight;"所需的lvalue;''这没有按照预期的方式工作,任何人都可以指向正确的方向吗?
#include <iostream>
int main()
{
double weight;
int planetnumber;
double otherweight;
std::cout << "Enter weightn";
std::cin >> weight;
std::cout << "Please select your arenan";
std::cin >> planetnumber;
switch (planetnumber)
{
case 1:
weight * 0.78 = otherweight;
break;
case 2:
weight * 0.39 = otherweight;
break;
case 3:
weight * 2.65 == otherweight;
break;
case 4:
weight * 1.17 = otherweight;
break;
case 5:
weight * 1.05 = otherweight;
break;
case 6:
weight * 1.23 = otherweight;
break;
default:
std::cout << "Not a valid inputn";
break;
}
std::cout << "your weight is " << otherweight << std::endl;
}
在c/c 中,结果在左侧,方程式在右侧。您只需要转置例如。
otherweight = 0.78 * weight;
相关文章:
- 用C++中的一个变量定义一个常量
- 变量定义到C++布尔值转换
- 未声明的标识符错误,但变量定义正确 (?)
- C++多线程程序:变量定义为类成员的隔离错误
- 将变量定义为静态时,为什么可以多次定义它
- 初始值设定项列表与构造函数赋值与变量定义
- 如何根据传递给函数的变量定义特征矩阵大小
- C++ 描述如何使用来简化变量定义
- 如何转发声明依赖于变量定义的类,而变体定义又依赖于模板化类?
- 是否修改其声明语句中的变量定义良好
- 使用类的其他成员变量定义类的成员变量数组
- 是否可以通过全局变量定义具有可变参数数的函数中的参数数量
- 元组 std::get() 不适用于变量定义的常量
- 全局使用变量定义和C 声明
- C++变量定义中的易失性类型量词位置
- 将变量定义为数组和正确的语法
- 多个,包括具有变量定义的头文件
- 调用构造函数,并将成员作为参数解析为变量定义
- 逗号分隔变量定义中关系前的序列
- 如何使用命名变量定义常量右值引用参数的默认值