小编mat*_*121的帖子

使用二次公式的简单二次方程计算器

我想知道是否有人可以帮助我解决这个(初学者)问题。我正在创建一个非常基本的二次方程计算器。我在下面列出了我的代码以及注释(代码片段顶部的那些解释了我必须做什么)。我在网上查看了多种解决方案并尝试了自己,但似乎我不断收到不正确的 x1 和 x2 值。如果有人能指导我,我会非常高兴。干杯。

/* 
create program to calculate x for quadratic equation. (a, b and c)
1) create function which prints out roots of quad equation.
2) throw exception if b2 - 4ac is less than 0.
3) call the function from main.
*/

#include <iostream>
#include <cmath>
#include <string>

using namespace std;

double roots() { //return type, function name, parameters and body of function.
    double a = 0, b = 0, c = 0, x1, x2;
    double …
Run Code Online (Sandbox Code Playgroud)

c++ calculator

3
推荐指数
1
解决办法
157
查看次数

向量和函数练习

我有一个关于这个程序的问题。我是编程和 C++ 的初学者,我试图弄清楚两件事。

  1. 为什么这个程序没有编译(错误:使用未初始化的内存“总计” - 我将它定义为一个变量??)。

  2. 有人能解释一下 main ( sumUpTo)之外的函数是如何工作的吗?具体& vectotal,因为我从来没有见过他们。谢谢。

/* 1) read in numbers from user input, into vector    -DONE
    2) Include a prompt for user to choose to stop inputting numbers - DONE
    3) ask user how many nums they want to sum from vector -
    4) print the sum of the first (e.g. 3 if user chooses) elements in vector.*/

#include <iostream>
#include <string>
#include <vector>
#include <numeric> //for accumulate

int …
Run Code Online (Sandbox Code Playgroud)

c++ stdvector c++-standard-library

1
推荐指数
1
解决办法
77
查看次数

标签 统计

c++ ×2

c++-standard-library ×1

calculator ×1

stdvector ×1