如何让C ++解决输入值的方程? [英] How to have C++ solve the equation for an input value?

查看:160
本文介绍了如何让C ++解决输入值的方程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被卡住试图找出一种方法使用C ++来解决一种情况,用户使用cin输入值,然后让计算机解决方法来获取cin的值,给定的格式给出。一个超快的例子写在下面..是的我知道有很多代码丢失...但概念是有..

I am stuck trying to figure out a way using C++ to solve a situation where the user inputs a value using cin and then have the computer solve for a way to get the value of cin, given that the format is given. a super fast example is written below.. yes i know there is a lot of code missing... but the concept is there..

int x;
int y;
int w;

int x = 30 < w < 50;
int y = 60 < w < 90;

cin >> input;

x + y = input;

cout << x;
cout << y;

当然,虽然x + y不在右侧的左侧。所以我不能只写x + y =输入..所以我会如何解决x + y =输入?另外,我想要x和y在列出的数字之间,这限制了这些输入之间的数字。但是在我的实际编码我做了一个函数。

Naturally though x + y cant be on the lvalue on the right. so i cant just write x + y = input.. so how would i have it solve x + y = input? Additionally I want x and y to be between the numbers listed, which limits the numbers between those inputs.. however in my actual coding i did this with a function.

学校还开始了吗?没有它不是家庭作业。 im教自己C ++ .. - Sean Holt 1分钟前编辑

has school even started yet? no its not homework. im teaching myself C++.. – Sean Holt 1 min ago edit

没有im只是想让计算机解决输入值的x / y如果x和y在函数中的指定值之间

No im just trying to figure a way of having the computer solve for x/y of an input value if x and y are between specified values in a function

推荐答案

看起来你认为C ++会为你解决方程式。它不会。 C ++是一种命令式的风格语言,它以 完全的概念为基础。

It looks like you think that C++ is going to solve equations for you. It won't. C++ is an imperative style language that is based around the concept of you telling it exactly what to do.

你必须找出如何解决x和y,以便你可以做一个算法。这个算法就是你的程序。

You will have to figure out how to solve for x and y so that you can make an algorithm. This algorithm is then what you make your program from.

还有其他语言,你可以在某种意义上描述你想要的,让编译器或运行时计算出如何为你得到它。 C ++不是其中之一。

There exists other languages in which you can in a sense describe what you want and have the compiler or runtime figure out how to get it for you. C++ is not one of them.

解决你的特定问题的不同方法是建立一个方程系统并解决它。或者使用强力方法并迭代x和y的值,以找出哪些值匹配。

Different ways to solve your particular problem would be to set up an equation system and solving that. Or do brute force approach and iterate through the values of x and y in order to find out which values match.

这篇关于如何让C ++解决输入值的方程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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