You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.1 KiB
C++
40 lines
1.1 KiB
C++
#include <iostream>
|
|
#include <cmath>
|
|
|
|
int check_number(std::string number, double* checked_number) {
|
|
std::size_t pos;
|
|
*checked_number = std::stoi(number, &pos); // how to properly type check? or is that not necessary?
|
|
return 0;
|
|
}
|
|
|
|
int main(int argc, char *argv[]) {
|
|
if (argc < 4) {
|
|
std::cout << "No/Not enough parameters given." << std::endl;
|
|
return -1;
|
|
}
|
|
double a, b, c;
|
|
int check = check_number(argv[1], &a) & check_number(argv[2], &b) & check_number(argv[3], &c);
|
|
if (check < 0) {
|
|
std::cout << "Something went wrong. :/" << std::endl;
|
|
return check;
|
|
}
|
|
double p = b/a;
|
|
double q = c/a;
|
|
|
|
double w = (p*p / 4) - q;
|
|
if (w < 0) {
|
|
std::cout << "No real solutions." << std::endl;
|
|
return 0;
|
|
}
|
|
|
|
double x_1 = -(p / 2) + sqrt(w);
|
|
double x_2 = -(p / 2) - sqrt(w);
|
|
|
|
if (x_1 == x_2)
|
|
std::cout << "Double zero at x = " << x_1 << std::endl;
|
|
else
|
|
std::cout << "Zeroes found at x_1 = " << x_1 << " and x_2 = " << x_2 << std::endl;
|
|
|
|
return 0;
|
|
}
|