Classes/csci218/Labs/Lab3/lab3.c
2024-09-09 15:21:47 -04:00

81 lines
2.1 KiB
C

/* Name: Garrett Haldrup
<lab3.c>
Problem: Have two functions called in main
Function1(C2F): Convert Fahrenheit to Celcius
Function2(getShootingPercent): Calculate shooting percentage based on shots attempted and succeded.
Certification of Authenticity:
I certify that this assignment is entirely my own work.
*/
#include <stdio.h>
void greet();
void C2F();
void getShootingPercent();
int main() {
// call function greet()
greet();
/* Activity 1. write your code to call C2F() */
C2F();
/* Activity 2. write your code to call getShootingPercent() */
getShootingPercent();
return 0;
}
void greet(){
printf("Hello, world!\n");
}
void C2F() {
// State purpose of function
printf("This function will convert Celcius to Fahrenheit\n");
// Declare the Fahrenheit and Celcius float variables
float tempF, tempC;
// Scan in Fahrenheit value from user
printf("Please enter degrees Celcius(C°): ");
scanf("%f", &tempC);
// Convert Fahrenheit to Celcius using the equation C = 5.0/9.0(F - 32)
tempF = (tempC * (9.0 / 5.0)) + 32;
// Output calculated Celcius tempature
printf("The tempature %.1fC° converted to Fahrenheit(F°) is: %.1fF°\n", tempC, tempF);
}
void getShootingPercent() {
// State purpose of function
printf("This function will calculate your shooting percentage\n");
// Declare shots attempted and success as int and the shooting percentage as float
int shotsAttempt, shotsSuccess;
float shootPer;
// Scan in shots attempted and shots success from user
printf("Please enter number of shots attempted: ");
scanf("%d", &shotsAttempt);
printf("Please enter how many of the %d shots were succesfull: ", shotsAttempt);
scanf("%d", &shotsSuccess);
// Check to see if data entered is correct and calculate the percentage by (shotsSuccess/shotsAttempt) * 100
if (shotsSuccess > shotsAttempt) {
printf("Invalid Entry: More success than attempts\n");
} else {
shootPer = ((float)shotsSuccess / shotsAttempt) * 100;
// Output shot percentage to user
printf("Your shooting percentage is: %.1f%%\n", shootPer);
}
}