✨ finished assignment 2.2
parent
736f86a1e4
commit
9770f873de
@ -0,0 +1,39 @@
|
||||
#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;
|
||||
}
|
Loading…
Reference in New Issue