#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int numOfInst, totalCycles, totalInst, clockRate;
int cpiClass[100], instCount[100];
void parameters(){
    totalInst = 0;
    totalCycles = 0;
    int counter;

    printf("Enter the number of instruction classes: \n");
    scanf(" %d", &numOfInst);
    printf("Enter the frequency of the machine (MHz): \n");
    scanf(" %d", &clockRate);

    for (counter = 0; counter < numOfInst; counter++){
        printf("Enter CPI of class %d: ", counter + 1);
        scanf(" %d", &cpiClass[counter]);
        printf("Enter instruction count of class %d (millions): ", counter + 1);
        scanf(" %d", &instCount[counter]);

        totalInst += instCount[counter];
        totalCycles += cpiClass[counter] * instCount[counter];
    }
    return;
}

/*float avgCPI(){
float avg = totalCycles / ((float)totalInst);
return (avg);
}

float execTime(){
float time = (totalCycles / ((float)clockRate)) * 1000;
return (time);
}

float calcMips(){
float mips = totalInst / (totalCycles / ((float)clockRate));
return (mips);

}*/
void printParam(){
    int i;
    printf("-------------------------\n");
    printf("| Class\t | CPI\t |Count\t |\n");
    for (i  = 0; i < numOfInst; i++){
    printf(" %d\t%d\t%d\t\n", i+1,cpiClass[i],instCount[i]);
    }
    /*totalCycles[i], totalInst[i]);*/
return;
}

/*void printPerformance{
}*/
int main()
{
    int option;
    do {
        printf("\nPerformance assessment: ");
        printf("\n-----------------------");
        printf("\n1) Enter parameters: ");
        printf("\n2) Print table of parameters: ");
        printf("\n3) Print table of performance ");
        printf("\n4) Quit \n");
        scanf(" %d", &option);

        switch (option){
        case 1: parameters();
            break;
        case 2: printParam();
            break;
        case 3:
            break;
        case 4:
            break;
        default: printf("Invalid input, please enter a number from 1-4 ");
        }
    }while(option != 4);
    return 0;
}