DIGIT-ARC read-only archive · snapshot: July 23, 2026

program compiles but does'nt run

15 posts · originally from https://geek.digit.in/community/threads/program-compiles-but-doesnt-run.26214/

M
makarand Original post #1
Mar 29, 2006 at 6:55 PM
Hey guys help me
I use XP and just made a program in C
when i compile it it shows 0 erros and 0 warnings
when i run the program the first line is displayed "Enter the amount:"
when i do so an erro comes up showing a prolem has occured and we're sorry for the inconvinience
help me
M
Mar 29, 2006 at 11:40 PM
Mate, without the source code how are we supposed to find out the problem? After all it has to be a coding error... right?
::vicky::
Mar 30, 2006 at 8:38 AM
ya first show the coding i think ur code is ok as u say that code gets compiled but it is a windows error
S
Mar 30, 2006 at 9:47 AM
^^ There are two types of errors in programming - compile errors and runtime errors. Compile errors are syntax errors that are caught during compilation of the program. .. The runtime errors are those that are caused by logical errors...
Since your program compiled without problem, you prob. dont have compile errors. Runtime errors can be caused by invalid pointers, division by zero, infinite loops,etc... That seems to be what you have... So, we will need the code to identify what the problem is...

Arun
M
Mar 30, 2006 at 6:56 PM
dear friends its justb a simple program of finding simple interest
S
Mar 30, 2006 at 7:28 PM
^^^ Post the code because the error most probably lies in the logic somewhere... Only if you post the code can we test and identify the problem...

Arun
Gaurav
Gaurav #7
Mar 30, 2006 at 10:39 PM
most probably your installation of C could be corrupted.
mayanksharma
Mar 31, 2006 at 12:20 AM
it seems that your installation for c is not properly done.this thing usually occurs whenever there is corruption. You can also try program compatability mode though!
M
Mar 31, 2006 at 9:03 AM
#inlcude<stdio.h>
int main()
{
float p,n,r,si;
printf("Enter Principal:",p);
scanf("%f",p);
printf("Enter Years:",n);
scanf("%f",n);
printf("Enter Rate:",r);
scanf("%f",r);
si = p*n*r/100;
printf("Simple Interest:%f",si);
getchar();
}
QwertyManiac
Mar 31, 2006 at 9:26 AM
makarand said:
#inlcude<stdio.h>
int main()
{
float p,n,r,si;
printf("Enter Principal:",p);
scanf("%f",p);
printf("Enter Years:",n);
scanf("%f",n);
printf("Enter Rate:",r);
scanf("%f",r);
si = p*n*r/100;
printf("Simple Interest:%f",si);
getchar();
}
1. u cant use getchar() w/o including its headerfile (conio.h i think, been a long time since C progging)
2. Printf statements that dont display a variable dont need a parameter for that i think.
Code:
printf("Enter Principal:",p); is wrong, printf("Enter Principal:"); is just fine because u are using the scanf statement in the next line
M
Mar 31, 2006 at 11:15 AM
The Solution

QwertManiac said:
u cant use getchar() w/o including its headerfile (conio.h i think, been a long time since C progging)

Yes mate, it's been a long time since you left C programming 'coz the header file <conio.h> isn't needed for getchar(). It's needed for getch() which is what should have been used here.

QwertManiac said:
Printf statements that dont display a variable dont need a parameter for that i think.

Correct! The 2nd parameters aren't needed here but they are not the source of the problem 'coz by nature printf() ignores any "extra" parameters passed to it beyond what's needed by the format string.

it seems that your installation for c is not properly done.
most probably your installation of C could be corrupted.

Now, I don't know how they reached to this conclusion but not everything can be solved by going the "uninstall-then-re-install" way.

So, what's the error? It's actually a very very very simple error and half of you are gonna knock on your heads when you'll know what it is.

scanf() needs variable addresses not their values.

p, n, and r are not pointers. They are simple variables.

So, to pass their addresses to scanf() you have to precede them with an ampersand '&' like &p, &n and &r.

Just modify the original scanf() statements as follows and the program would run fine:

scanf ("%f", &p) ;
scanf ("%f", &n) ;
scanf ("%f", &r) ;

@ makarand :
One more thing, to make your program wait for a keystroke at the end you need to use getch() with #include <conio.h>. getchar() won't work.
A
Mar 31, 2006 at 11:49 AM
You gotta put & with scanf
scanf("%f",&p);
mayanksharma
Mar 31, 2006 at 9:37 PM
you have to provide the address pass medium to the variables defined.
do it like this:-

scanf("%f",&r);
and make sure to return value to 0 in the end of the program,if you have included int before main.This will reduce your warnings....
QwertyManiac
Mar 31, 2006 at 10:30 PM
Oh, missed readin that part, sorry :oops: C, I guess I wil l have to start over again :lol:
M
makarand #15
Apr 1, 2006 at 7:45 PM
Thank You guys