Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have having trouble degbugging and fixing my compiler errors. In line 14, I ge

ID: 3601158 • Letter: I

Question

I have having trouble degbugging and fixing my compiler errors.

In line 14, I get the error: expected expression before 'int'.

In line 19, I get the error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token.

In line 19, I also get the warning: unused variable ‘i’. Don't know why since I am placing the number read by scanf into the array at position i during each iteration.

And In line 6, I get the warning: unused variable "intArray'. Don't know why since I am accessing the array in the for loop and assigning it the number scanf reads in.

1 2 #include #include 4 int main (void) { 6 int intArray 20 ]; 7 int numSort; 9 printf ( "Welcome to Project#1! "); 10 11 printf( "Please enter how many numbers you want to sort (up to 20): "); 12 scanf ("Si", &numSort;); 14 if ( int *numSort

Explanation / Answer

This is the code that I ve executed successfully, I have not used pointers here.

Error: In line 14, I get the error: expected expression before 'int'. -->

You are trying to declare an int type variable where you are not allowed for any declaration i.e inside if condition.

Error: In line 19, I get the error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token. -->

This error is caused because you are using ',' (comma) and not ';' in for loop. The ; seperates the three condition in for loop

The other errors i didn't get. So can't comment on that.

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

int main(void) {
int intArray[20];
int numSort;
  

printf("Welcome to the project#1! ");
printf("Please enter how many numbers you want to sort(upto 20) ");
scanf("%i", &numSort);

if(numSort <=2 )
{
printf("Numbers are already sorted! ");
exit(EXIT_SUCCESS);
}

for(int i = 0; i < numSort; ++i)
{
printf("Please enter the next number: ");
scanf("%d", &intArray[i]);
}
}