-
Problems compiling
Hi people. I'm new in this C programming issue and I have had some problems. It happens with Code::Blocks. When I complete my project and run the program it has no problem. I can type in the data, numbers, letters or whatever to make it work, but once I press Enter it jumps to a new line and does nothing at all. I even have to close the window with the X. I have an example with a basic program that finds a quotient and the rest with two numbers the user chooses. I don't know if it is a problem with the IDE or with my hideous coding, but I'd appreciate if you could give me a hand. Thanx.
Code:
#include <stdio.h>#include <conio.h>
void div(int a, int b)
{
int i,result=0,rest=0,p;
for(i=1;i=a;i++)
if((i*b)<a)
result=i;
else
p=result*b;
rest=a-p;
printf("The quotient is %d and the reminder is %d",result,rest);
return;
}
int main()
{
int a,b;
printf("Please type the dividend: \n");
scanf("%d",&a);
printf("Now, type the divisor. REMEMBER TO CHOOSE A SMALLER NUMBER: \n");
scanf("%d",&b);
div(a,b);
return 0;
}
-
-
Not enough blank lines. You should have no fewer than 13 blank lines separating every line of code. In all seriousness though, if you clean up your code (remove extraneous blank lines and fix indenting) it will help you find your issue.
-
Do not use conio.h the header library is not supported in the standard
and contains outdated functions. Also, you do not need to have a return
statement in a void-returning function unless it's used as an alternative exit
path.
-
-
Quote:
Originally Posted by
jlb
Why is it problematic?
Because assignment(=) is totally different to equality(==).
-
Also, make sure you look up how to compile in Code::Blocks with the flags -Wall -pedantic. They'll help you catch a lot of bugs and ensure that your code is standards-compliant.