This is a programming practice that our teacher gave us, and I would appreciate if someone can look over my program and tell me if I did a good job.
Basically, the context is I joined a company and am supposed to write a program in C that takes three inputs (ft of steel, number of ball bearings, and lbs of bronze), and returns how many bells and whistles can be made the next day.
Making a whistle requires 0.5 ft of steel and 1 ball bearing. Making a bell requires 1.10 lbs of bronze (.75 lbs of bronze and 1 clapper (.35 lbs of bronze)).
This is the program I have written. I apologize if it seems messy.
#include <stdio.h>
#include <stdbool.h>
void PrintLine();
int CalculateWhistles(int steel, int bearings);
int CalculateBells(int bronze);
int main() {
bool runProgram = true;
int runAgain = 0;
while (runProgram == true) {
int ftSteelIn = 0;
int numBallBearingIn = 0;
int ibsBronzeIn = 0;
printf("\n\n"); // Formatting...
PrintLine();
printf(" How many feet of steel was received today: "); // Steel received
scanf("%d", &ftSteelIn);
printf(" How many ball bearings were received today: "); // Ball bearings received
scanf("%d", &numBallBearingIn);
printf(" How many pounds of bronze was received today: "); // Bronze received
scanf("%d", &ibsBronzeIn);
PrintLine(); // Print line
PrintLine(); // Print line
// Print company logo and program title
printf(" Acme Corporation\n");
printf(" Product Report\n");
PrintLine();// Print line
// Print number of bells and whistles
printf(" Number of Bells %d\n", CalculateBells(ibsBronzeIn));
printf(" Number of Whistles %d\n", CalculateWhistles(ftSteelIn, numBallBearingIn));
PrintLine(); // Print line
PrintLine();
printf("\n\n");
PrintLine();
// Ask the user if they would like to run the program again
printf(" Would you like to run the program again? ('1' for yes, '2' for no): ");
scanf("%d", &runAgain);
PrintLine();
// If user does not say 'yes', end the program and say goodbye
if (runAgain != 1) {
printf("\n Exitting the program. Have a good day.\n\n");
PrintLine();
runProgram = false;
}
}
return 0;
}
void PrintLine() {
int i = 0;
printf(" ");
while (i <= 70) {
printf("-");
i++;
}
printf("\n");
}
int CalculateWhistles(int steel, int bearings) {
steel = steel / 0.5;
if (steel < bearings) {
return steel;
}
else if (bearings < steel) {
return bearings;
}
}
int CalculateBells(int bronze) {
int bells = bronze / 1.1;
return bells;
}
It runs fine with no errors. There is a second part where I calculate the remainder, but I want some feedback before I go on to that part.
Any advice would be appreciated, how to make it more efficient or anything like that (I'm just learning C).