Skip to content
Binary file added a.exe
Binary file not shown.
83 changes: 63 additions & 20 deletions calculator.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Author:
* Date:
* Author: Alisha
* Date: 5-10-2023
*
* This programs provides basic calculator functionality
* allowing a user to enter two operands and to compute
Expand All @@ -10,6 +10,63 @@
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
double calculator( int choice, double a, double b );
double calculator( int choice, double a, double b ){
double result= 0.0;
if(choice == 1)
{
result = a + b;
printf("Result: %.2f\n", result);

}
else if(choice == 2)
{
result = a - b;
printf("%.2f", result);

}
else if(choice == 3)
{
result = a * b;
printf("Result: %.2f\n", result);


} //TODO: handle this case (division)
else if(choice == 4)
{
if (b != 0) {
result = a / b;
printf("Result: %.2f\n", result);

} else {
printf("Cannot divide by zero.\n");
}


}//TODO: handle this case (minimum)
else if(choice == 5)
{
result = fmin(a, b);
printf("Result: %.2f\n", result);


}//TODO: handle this case (log_a(b))
else if(choice == 6)
{
if (a > 0 && a != 1) {
result = log(b) / log(a);
printf("Result: %.2f\n", result);
} else {
printf("Invalid base for logarithm.\n");
}

}
else
{
printf("Please input a valid operator next time");
}
return result;
}

int main(int argc, char **argv) {

Expand All @@ -30,23 +87,9 @@ int main(int argc, char **argv) {
printf("(5) Minimum\n");
printf("(6) log_a(b)\n");
scanf("%d", &choice);

if(choice == 1) {
printf("%f", a + b);
} else if(choice == 2) {
result = a - b;
printf("%f", result);
} else if(choice == 3) {
//TODO: handle this case (multiplication)
} else if(choice == 4) {
//TODO: handle this case (division)
} else if(choice == 5) {
//TODO: handle this case (minimum)
} else if(choice == 6) {
//TODO: handle this case (log_a(b))
} else {
printf("Please input a valid operator next time");
}

result= calculator(choice, a, b);
printf("Result: %.2f\n", result);


return 0;
}
60 changes: 53 additions & 7 deletions leapYear.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ int main(int argc, char **argv) {
numPassed = numPassed + 1;
}

year = 2001;
year = 2002;
printf("Test Case 2: year = %d: ", year);
if(isLeapYear(year)) {
printf("FAILED!\n");
Expand All @@ -49,7 +49,7 @@ int main(int argc, char **argv) {
numPassed = numPassed + 1;
}

year = 2100;
year = 2006;
printf("Test Case 3: year = %d: ", year);
if(isLeapYear(year)) {
printf("FAILED!\n");
Expand All @@ -58,26 +58,72 @@ int main(int argc, char **argv) {
printf("PASSED!\n");
numPassed = numPassed + 1;
}

//TODO: write *at least* 3 more of your own
// test cases here, they should all pass!

year = 1600;
printf("Test Case 4: year = %d: ", year);
if(!isLeapYear(year)) {
printf("FAILED!\n");
numFailed = numFailed + 1;
}
else
{
printf("PASSED!\n");
numPassed = numPassed + 1;
}

year = 2024;
printf("Test Case 5: year = %d: ", year);
if(!isLeapYear(year))
{
printf("FAILED!\n");
numFailed = numFailed + 1;
}
else
{
printf("PASSED!\n");
numPassed = numPassed + 1;
}

year = 2020;
printf("Test Case 6: year = %d: ", year);
if(!isLeapYear(year))
{
printf("FAILED!\n");
numFailed = numFailed + 1;
}
else
{
printf("PASSED!\n");
numPassed = numPassed + 1;
}

printf("\n\n");
printf("Summary:\n");
printf("Number of test cases passed: %d\n", numPassed);
printf("Number of test cases failed: %d\n", numFailed);
printf("Percentage Passed: %.2f%%\n", (double) numPassed / (numPassed + numFailed) * 100.0);

if(reportPass) {
if(reportPass)
{
return numPassed;
} else {
return numFailed;
}
}

int isLeapYear(int year) {
//TODO: Write your logic here
//TODO: Write your logic here
// The year is stored in the variable year
// Your function should return true (1) if it represents a leap year
// and false (0) if it does not.
int isLeapYear(int year) {
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
{
return 1;
}
else
{
return 0;
}

}
28 changes: 25 additions & 3 deletions taxes.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,31 @@ int main(int argc, char **argv) {
printf("How many children do you have? ");
scanf("%d", &numChildren);
}

//TODO: compute the tax, child credit, and total tax here

if (agi <= 19900)
{
tax = agi * 0.1;
}
else if (agi <= 81050)
{
tax = 2000 + (agi - 19900) * 0.15;
}
else if (agi <= 172750)
{
tax = 7000 + (agi - 81050) * 0.2;
}
else
{
tax = 17000 + (agi - 172750) * 0.25;

}
// Compute the child credit based on the number of children
childCredit = numChildren * 1000;

// Compute the total tax
totalTax = tax - childCredit;

//display result
printf("\nTax Calculation:\n");
printf("AGI: $%10.2f\n", agi);
printf("Tax: $%10.2f\n", tax);
printf("Child Credit: $%10.2f\n", childCredit);
Expand Down