DESIRED OUTPUT:
Input Value to find factors for? 10
The number 10 has 1,2,5 and 10 as its factors
The number 10 has 4 factors
Try again y/n ?
CURRENT OUTPUT:
Input value to find factors for ? 10
The number 10 has 1 and 10 as it factors
The number 10 has 2 and 10 as it factors
The number 10 has 5 and 10 as it factors
The number 10 has 10 and 10 as it factors
The number 10 has -1 and 10 as it factors
The number 10 has -2 and 10 as it factors
The number 10 has -5 and 10 as it factors
The number 10 has -10 and 10 as it factors
My Current Code
#include <stdio.h> // printf, scanf, getchar
#include <stdlib.h> // system
int list_mult(int value);
int main()
{
int input_value;
char again;
do {
printf("Input value to find factors for ? ");
scanf("%d", &input_value);
list_mult(input_value);
printf("\nTry again y/n ? ");
scanf(" %c", &again);
} while (again == 'y');
}
int list_mult(value) {
int i;
int count = 0;
printf("\nThe number %d has", value);
for (i = 1; i <= (value / 2); i++)
{
if (value%i == 0)
{
printf(" %d,", i);
count++;
}
}
printf(" and %d as it factors", value);
printf("\nThe number %d has %d factors", value, count);
return(count + 1);
}
Problems:
1st : do-while loop (again) not work
2nd: "The number 10 has 1,2,5 and 10 as its factors" . Do not know how to show "i" separate by commas.
3rd: Last print statement (Count) does not work
Edit: all above Problem is solved. And the above code works perfectly on CodeBlock
The problem I got now is I use CodeBlock and my code works perfectly. But when I use Microsoft Studio at School (Iam only allowed to use MS at school), MS shows Error as below
C2065 'value': undeclared identifier - Line 29
C2365 'list_mult': redefinition; previous definition was 'function' - Line 29
C2448 'list_mult': function-style initializer appears to be a function definition
Edit2: Compiler Error Solved. Everything works greatly now. Thank you