finished assignment 2.2

main
Isabell Pflug 2 years ago
parent 736f86a1e4
commit 9770f873de

@ -15,7 +15,7 @@ int guess(int to_guess) {
int guess_number;
int check = check_number(guess, &guess_number);
if (check < 0) {
std::cout << "Something seems to have went wrong." << std::endl;
std::cout << "Something went wrong. :/" << std::endl;
return check;
}
if (!(guess_number == to_guess)) {

@ -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;
}

@ -2,4 +2,4 @@ cmake_minimum_required(VERSION 3.11.4)
project (01)
add_executable(02_1 02_1.cpp)
#add_executable(01_2 01_2.cpp)
add_executable(02_2 02_2.cpp)

Loading…
Cancel
Save