Quadratic Equation Solver §
#include <iostream>
#include <cmath>
int main()
{
// caleb b
// quadratic equation solver
double a, b, c, x1, x2, discriminant;
std::cout << "Enter a: " << std::endl;
std::cin >> a;
std::cout << "Enter b: " << std::endl;
std::cin >> b;
std::cout << "Enter c: " << std::endl;
std::cin >> c;
discriminant = pow(b, 2) - 4 * a * c;
// check if there are zero, one, or two solutions
if (discriminant > 0)
{
x1 = (-b + sqrt(discriminant)) / (2 * a);
x2 = (-b - sqrt(discriminant)) / (2 * a);
std::cout << "There are two solutions: " << x1 << " and " << x2 << std::endl;
}
else if (discriminant == 0)
{
x1 = (-b + sqrt(discriminant)) / (2 * a);
std::cout << "There is one solution: " << x1 << std::endl;
}
else
{
std::cout << "There are no real solutions." << std::endl;
}
return 0;
}
Leap Year Calculator §
#include <iostream>
#include <cmath>
int main()
{
// caleb b
// leap year calculator
int year;
std::cout << "Enter a year: " << std::endl;
std::cin >> year;
if (year % 4 == 0 && year % 400 == 0) {
std::cout << "That is a leap year." << std::endl;
} else if (year % 4 == 0 && year % 100 != 0) {
std::cout << "That is a leap year." << std::endl;
} else {
std::cout << "That is not a leap year." << std::endl;
}
return 0;
}
Change Calculator §
#include <iostream>
#include <cmath>
int main()
{
// caleb b
// change calculator
int value;
int quarters;
int dimes;
int nickels;
int pennies;
std::cout << "Enter the amount of change in cents: " >> std::endl;
std::cin >> value;
if (value < 0 || value > 100) {
std::cout << "Invalid input" << std::endl;
return 0;
}
quarters = value / 25;
value = value % 25;
dimes = value / 10;
value = value % 10;
nickels = value / 5;
value = value % 5;
pennies = value;
std::cout << "Quarters: " << quarters << std::endl;
std::cout << "Dimes: " << dimes << std::endl;
std::cout << "Nickels: " << nickels << std::endl;
std::cout << "Pennies: " << pennies << std::endl;
return 0;
}