I'm having an issue finding the infinite loop in my code if someone can help that would be great.
Code:
#include <stdio.h>
int main() {
int instructionCount[100], totalInstructions = 0, cpi[100], noOfClass = 0, frequency = 0, ch = 0;
float averageCpi = 0, executionTime, mips;
const long MILLION = 1000000;
do {
printf("\n 1) Enter Parameters(");
printf("\n 2) Print Results");
printf("\n 3) Quit");
printf("\n Enter Selection: ");
scanf("%d", &ch);
if (ch == 1) {
printf("\n Enter the number of instruction classes: ");
scanf("%d", &noOfClass);
printf("\n Enter the frequency of the machine (MHz): ");
scanf("%d", &frequency);
for (int i = 0; i < noOfClass; ++i) {
printf("\n Enter CPI of class %d : ", (i + 1));
scanf("%d", &cpi[i]);
printf("\n Enter instruction count of class %d (millions): ", (i + 1));
scanf("%d", &instructionCount[i]);
totalInstructions += instructionCount[i];
}
}
else if (ch == 2) {
printf("\nFREQUENCY (MHz): %d", frequency);
printf("\nINSTRUCTION DISTRIBUTION");
printf("\nCLASS \t CPI \t COUNT");
for (int i = 0; i < noOfClass; ++i) {
printf("\n %d \t %d \t %d", (i + 1), cpi[i], instructionCount[i]);
averageCpi += (cpi[i] * instructionCount[i] * MILLION);
}
averageCpi = averageCpi / (totalInstructions * MILLION);
mips = (frequency * MILLION) / (averageCpi * MILLION);
executionTime = ((averageCpi * (totalInstructions * MILLION)) / (frequency * MILLION)) * 1000;
printf("\n PERFORMANCE VALUES");
printf("\n AVERAGE CPI \t %.2f", averageCpi);
printf("\n TIME (ms) \t %.2f", executionTime);
printf("\n MIPS \t %.2f", mips);
printf("\n");
}
} while (ch != 3);
return 0;
}