Question
I keep getting an infinite loop for my program but I cant seem to find whats causing it. I. thought it might be my switch
I keep getting an infinite loop for my program but I cant seem to find whats causing it. I. thought it might be my switch statement but I can't find any syntax errors. Thank you.
#include
/* declare global var's, including total cycles,
total instruction count, and clock cycle rate */
float total_cycles;
int total_instructions;
float clock_rate;
/*********************************************************/
void enter_params()
{
/* declare local var's and initialize*/
total_cycles = 0.0;
total_instructions = 0;
int number_classes;
float cpi_i;
int instr_i;
/* prompt for # instruction classes & clock cycle rate of machine */
printf("Enter number of instruction classes");
scanf("%d", &number_classes);
printf("Enter the frequency of the machine (GHz)");
scanf("%f", &clock_rate);
/* for each instruction class, prompt for CPI of class and instruction count */
for(int i =1; i<= number_classes; i+=1){
printf("Enter the CPI of the class:%d ", i);
scanf("%f", &cpi_i);
printf("Enter instruction count of class %d (billion) ", i);
scanf("%d", &instr_i);
/* update values in appropriate glocal var's */
total_cycles += cpi_i * (float)(instr_i);
total_instructions += instr_i;
}
return;
}
/*********************************************************/
void calc_exectime()
{
/* declare local var's */
float exectime;
/* Calculate execution time and print result */
exectime = (total_cycles)/(clock_rate); //1000?
printf("The execution time of the sequence is: %f seconds", exectime);
return;
}
/*********************************************************/
void calc_mips()
{
/* declare local var's */
float MIPS;
float avg_cpi;
avg_cpi = total_cycles/(float)(total_instructions); //float?
/* Calculate MIPS and print result */
MIPS = clock_rate/(avg_cpi);
printf("The MIPS of the sequence is %.2f", MIPS);
return;
}
/*********************************************************/
void calc_avgcpi ()
{
/* declare local var's */
float avg_cpi;
avg_cpi = total_cycles/(float)(total_instructions);
/* Calculate average CPI and print result */
printf("The average of the sequence is: .%2f", avg_cpi);
return;
}
/*********************************************************/
int main()
{
int user_input;
int x =1;
/* until user chooses to quit, print menu,
select choice via switch statement and call appropriate function*/
while(x==1) {
printf("Measuring performance ");
printf("-------------");
printf("1. Enter Parameters ");
printf("2. Calculate Execution time of a sequence ");
printf("3. Calculate MIPS of a sequence ");
printf("4. Calculate average CPI of a sequence ");
printf("5. Quit program ");
printf("Enter choice");
scanf("%d", &user_input);
switch(user_input){
case 1: enter_params();
break;
case 2: calc_exectime();
break;
case 3: calc_mips();
break;
case 4: calc_avgcpi();
break;
case 5: return(0);
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started