1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
#include <conio.h>
#include <stdio.h>
#include <windows.h>
int main()
{
/* variables and objects declared here*/
int result, totalMines, mineNumber, yearOpened, yearClosed, totalProduction, count, mineLifespan;
int totalMineProduction=0, storedTotal=0, longestLifespan=0, longestLifespanNo=0;
float yearlyProduction;
int compare(int yrOpened, int yrClosed);
system("cls");
/* User enters the number of mines */
printf("\nPlease enter the number of mines: ");
scanf("%d",&totalMines);
/*For loop for entering data for each mine*/
for (count=1; count <= totalMines; count++, totalMineProduction, storedTotal, longestLifespan, longestLifespanNo)
{
printf("\n Please enter the number of the mine: ", count);
scanf("%d",&mineNumber);
printf("\n Please enter the year mine %d was opened: ", mineNumber);
scanf("%d",&yearOpened);
printf("\n Please enter the year mine %d was closed: ", mineNumber);
scanf("%d",&yearClosed);
result = compare(yearOpened, yearClosed);
while (result=1)
{
printf("\n The year closed is before the year opened. Please re-enter the year opened and year closed for the mine");
printf("\n Please enter the year mine %d was opened: ", mineNumber);
scanf("%d",&yearOpened);
printf("\n Please enter the year mine %d was closed: ", mineNumber);
scanf("%d",&yearClosed);
if (result=0)
{
printf("\n The year closed the same as the year opened. Please re-enter the year opened and year closed for the mine");
printf("\n Please enter the year mine %d was opened: ", mineNumber);
scanf("%d",&yearOpened);
printf("\n Please enter the year mine %d was closed: ", mineNumber);
scanf("%d",&yearClosed);
}
}
printf("\n Please enter the total ore production of mine %d in kg: ", mineNumber);
scanf("%d",&totalProduction);
/*Calculations for mine lifespans and production*/
mineLifespan = yearClosed - yearOpened;
printf("\n The lifespan of mine %d is %d", mineNumber, mineLifespan);
yearlyProduction = (float) totalProduction / mineLifespan;
printf("\n The average yearly ore production for mine %d is %0.2f", mineNumber, yearlyProduction);
/*Calculations for total combined mine production*/
storedTotal = totalProduction + totalMineProduction;
totalMineProduction = storedTotal;
/*If statement for adjusting longest lifespan*/
if(mineLifespan > longestLifespan)
{
longestLifespan = mineLifespan;
longestLifespanNo = mineNumber;
}
}
/*Printfs for showing total mine production and the mine number of the longest mine lifespan*/
printf("\n The total combined mine production is %d", totalMineProduction);
printf("\n The number of the mine with the longest lifespan is %d", longestLifespanNo);
getchar();
getchar();
}
int compare(int yrOpened, int yrClosed)
{
if(yrOpened = yrClosed)
{
return(0);
}
else if (yrOpened > yrClosed)
{
return(1);
}
else
{
return(-1);
}
}
|