Near Final
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
// Nicholas Pease
|
||||
// 14 FEB 2023
|
||||
// Monthly Budget Calculator
|
||||
|
||||
#include <stdio.h>
|
||||
#define FIXED_ADDITIONAL_MONTHLY_COSTS 581.99
|
||||
#define NUMBER_OF_INPUTS 6
|
||||
|
||||
int main() {
|
||||
// Declare Variables
|
||||
|
||||
// double array: inputs[]: Stores all numeric input information
|
||||
/*
|
||||
0: Monthly Expense Goal (USD)
|
||||
1: Rent Expenses Monthly (USD)
|
||||
2: Utilities Expenses Monthly (USD)
|
||||
3: Transportation Expenses Monthly (USD)
|
||||
4: Food Costs Expenses Monthly (USD)
|
||||
5: Car Payment (As set by #define above)
|
||||
*/
|
||||
// double totalExpenses: Stores the total expenditure
|
||||
double inputs[6], totalExpenses;
|
||||
// char name: Stores entered name
|
||||
char name[20];
|
||||
// char array inputString: Stores all input prompt string. Also corresponds to inputs in how data is stored
|
||||
char *inputStrings[6] = {"Monthly Expense Goal", "Rent","Utilities", "Transportation","Food Costs","Car Payment"};
|
||||
// init car payment to constant
|
||||
inputs[5] = FIXED_ADDITIONAL_MONTHLY_COSTS;
|
||||
|
||||
// Prompt for information
|
||||
printf("Please enter your name: ");
|
||||
fgets(name, 20, stdin);
|
||||
for (int i = 0; i < NUMBER_OF_INPUTS-1; i++) {
|
||||
printf("Enter %s (USD): ",inputStrings[i]);
|
||||
scanf(" %lf",&inputs[i]);
|
||||
}
|
||||
|
||||
// end initial inputs, generate and print budget chart
|
||||
printf("\nBudget Chart for %s",name);
|
||||
printf("%-30s %-30s %-30s\n","Expense:","Amount $","Percent %");
|
||||
for (int i=1; i< NUMBER_OF_INPUTS; i++) {totalExpenses+=inputs[i];}
|
||||
for (int i=1; i < NUMBER_OF_INPUTS; i++) {
|
||||
printf("%-30s %-30.2lf %-30.2lf\n",inputStrings[i],inputs[i],(inputs[i]/totalExpenses)*100);
|
||||
}
|
||||
double leftoverAmount = inputs[0] - totalExpenses;
|
||||
printf("\n%-30s %-30.2lf\n",inputStrings[0],inputs[0]);
|
||||
printf("%-30s %-30.2lf\n","Total Expenses",totalExpenses);
|
||||
printf("%-30s %-30.2lf\n","Leftover amount",leftoverAmount);
|
||||
printf("%s\n", (leftoverAmount > inputs[0]/5)? "Good job. You are saving enough!": "Try to save more!");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
// Nicholas Pease
|
||||
// 14 FEB 2023
|
||||
// Student Grade Tracking Program
|
||||
|
||||
#include <stdio.h>
|
||||
#define NUMBER_OF_SUBJECTS 4
|
||||
|
||||
int main() {
|
||||
/*
|
||||
char subjectCodes: Array of Characters to store the letter abbreviations of the subjects
|
||||
int studentGrades: Array of ints to store grades given to students as entered
|
||||
char studentName: "String" to store students name
|
||||
*/
|
||||
char subjectCodes[NUMBER_OF_SUBJECTS];
|
||||
int studentGrades[NUMBER_OF_SUBJECTS];
|
||||
char studentName[20];
|
||||
printf("Enter the student's name: ");
|
||||
fgets(studentName, 20, stdin);
|
||||
for (int i=0; i<NUMBER_OF_SUBJECTS; i++) {
|
||||
printf("Enter subject code %i and grade: ",i+1);
|
||||
scanf(" %c%i",&subjectCodes[i],&studentGrades[i]);
|
||||
}
|
||||
printf("\nFinal Grade for %s",studentName);
|
||||
printf("Total for ");
|
||||
// Initialize total to easily add to it as we loop over subject codes
|
||||
int totalOfAllGrades = 0;
|
||||
for (int i=0; i<NUMBER_OF_SUBJECTS; i++) {
|
||||
putchar(subjectCodes[i]);
|
||||
totalOfAllGrades+=studentGrades[i];
|
||||
}
|
||||
// Cast the dividend and divisor to double to allow for a precise result
|
||||
double average = (double)totalOfAllGrades / (double)NUMBER_OF_SUBJECTS;
|
||||
printf(": %d\n",totalOfAllGrades);
|
||||
printf("Average: %.2lf%%\n",average);
|
||||
// init letterGrade, which will store the computed average letter grade
|
||||
char letterGrade;
|
||||
if (average >= 90) {letterGrade = 'A';}
|
||||
else if (average >= 80) {letterGrade = 'B';}
|
||||
else if (average >= 70) {letterGrade = 'C';}
|
||||
else if (average < 70) {letterGrade = 'F';}
|
||||
printf("Grade: %c\n",letterGrade);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// Nicholas Pease
|
||||
// 14 FEB 2023
|
||||
// Temperature Conversion Program
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
// store input temperature in Fahrenheit
|
||||
double inputTemperatureInF;
|
||||
printf("Enter temperature in Fahrenheit = ");
|
||||
scanf("%lf",&inputTemperatureInF);
|
||||
// store converted temperature in Celsius
|
||||
double temperatureInC = (inputTemperatureInF-32)*5/9;
|
||||
printf("Temperature in Celsius = %.3lf C\n",temperatureInC);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user