### Cubic equations calculator in C++ Hello everyone!
I'm trying to write a C++ program that calculates the different x values for a cubic equation. I'm building it based on the Ruffini rule. However, when I run it, after I inserted the values, it just stops. Hope you can help me.

#include <iostream>
#include <string>
#include <cmath>
using namespace std;

class func {
public:
int a, b, c, d, a1, b1, c1, r = 0;
bool resolved = false;
int j, k, l = 0;

void get_nums() {
cout << "Use this calculator to solve polynomial equations with an order of 3 such as ax^3 + bx^2 + cx + d = 0 for x including complex solutions.\n\n";

cout << "Insert a: ";
cin >> a;
cout << "Insert b: ";
cin >> b;
cout << "Insert c: ";
cin >> c;
cout << "Insert d: ";
cin >> d;
}

void calculate_func() {
while (!resolved) {
int i = -100;
a1 = a * i;
b1 = b + a1;
c1 = c + i * b1;
r = d + i * c1;

if (r == 0 || i == 100*) {
if (j == 0) {
j = i;
i = i++;
}
else {
if (k == 0){
k = i;
i = i++;
}
else {
l = i;
resolved = true;
}
if (i == 100) {
resolved = true;
}
}
}
else {
i = i++;
}
}
}

void show_results() {
if (j == 0 && k == 0) {
cout << "Your x value doesn't exist.";
}
else if (j == k) {
cout << "Your x value is: " << j;
}
else{
cout << "Your x values are " << j << " and " << k << ".";
}
}
};

int main() {
func Func;
Func.get_nums();
Func.calculate_func();
Func.show_results();
} What do you mean "it just stops"?
Your program is going to do one of two things.
1. Loop forever in calculate_func().
2. Exit after showing results.
Which is it?

Have you used a debugger to step through your program?

PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button. A small point but `if (r == 0 || i == 100*)` contains an error.

Having solved that mystery, for anyone interested in trying to debug this un-commented program, the infinite loop is in the calculate_func()

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394`` ``````#include #include #include using namespace std; class func { public: int a, b, c, d, a1, b1, c1, r = 0; bool resolved = false; int j, k, l = 0; void get_nums() { cout << "Use this calculator to solve polynomial equations blah blah.\n\n"; cout << "Insert a: "; cin >> a; cout << "Insert b: "; cin >> b; cout << "Insert c: "; cin >> c; cout << "Insert d: "; cin >> d; } void calculate_func() { while (!resolved) { int i = -100; a1 = a * i; b1 = b + a1; c1 = c + i * b1; r = d + i * c1; std::cout << "Got this far\n"; if (r == 0 || i == 100) { if (j == 0) { j = i; i = i++; } else { if (k == 0) { k = i; i = i++; } else { l = i; resolved = true; } if (i == 100) { resolved = true; } } } else { i = i++; } } } void show_results() { if (j == 0 && k == 0) { cout << "Your x value doesn't exist."; } else if (j == k) { cout << "Your x value is: " << j; } else { cout << "Your x values are " << j << " and " << k << "."; } } }; int main() { func Func; Func.get_nums(); Func.calculate_func(); Func.show_results(); }``````
Last edited on In member function 'void func::calculate_func()':
45:28: warning: operation on 'i' may be undefined [-Wsequence-point]
52:32: warning: operation on 'i' may be undefined [-Wsequence-point]
67:24: warning: operation on 'i' may be undefined [-Wsequence-point]

Read up on how to increment a variable.

cpp.sh is not showing the warnings about uninitialised variables. Line 12 does not initialise all 3 variables. cane wrote:
cout << "Use this calculator to solve polynomial equations with an order of 3 such as ax^3 + bx^2 + cx + d = 0 for x including complex solutions.\n\n";

@cane, your code isn't doing anything of the sort.