PDA

View Full Version : whats wrong with




smogsy
Oct 15, 2008, 02:25 PM
#include <stdio.h>

int main ()
{ /*Most Important Part of the application*/

int Number; /*My Varibiles*/

/*Output Text*/
printf ("Hello Welcome to my First Application\n Please Input a Number Between 0 & 10\n");

/*input Text*/
scanf("%d",Number);

/*Tells them Their Number*/
printf("Your Number is" "%d",Number);

printf("OK You selected %d Correctly",Number);



return 0;
}




it runs ok but when inputting a number it goes to next line as it should but displays bus Error

thanks.



toddburch
Oct 15, 2008, 02:34 PM
Try this:

scanf("%d",&Number);

After you change it and see that it now works, come back here and tell me why so I know you understand why that fixed it.

Darkroom
Oct 15, 2008, 02:43 PM
besides missing the &number pointer...

/*Tells them Their Number*/
printf("Your Number is" "%d",Number);

weird quotes in there?

try:

/*Tells them Their Number*/
printf("Your Number is %d", Number);

you can also use %i for integers... i always found using %d a little odd, although it's way common, and they both do the exact same thing, i just find it easier to associate Integers with the letter I...

and don't forget the newline character "\n" after your sentence so the 2 output sentences don't run together:


printf("Your Number is %d\n", Number);

toddburch
Oct 15, 2008, 02:47 PM
Well, it is errant, but that's not the output the OP will get:


Hello Welcome to my First Application
Please Input a Number Between 0 & 10
4
Your Number is4OK You selected 4 Correctly
The Debugger has exited with status 0.

fimac
Oct 15, 2008, 02:52 PM
besides missing the &number pointer...

/*Tells them Their Number*/
printf("Your Number is" "%d",Number);

weird quotes in there?


Weird, perhaps, but the C compiler concatenates adjacent literal strings :)

smogsy
Oct 15, 2008, 02:55 PM
it works after inserting the & any reason why it saying 90k? the first time?

Your Number is 9OK You selected 9 Correctly
sorry still learning :D

itickings
Oct 15, 2008, 03:09 PM
it works after inserting the & any reason why it saying 90k? the first time?

It is actually saying 9 and then OK immediately afterwards. You have to specifically tell the computer to advance to the next row. If you don't, it will continue to write stuff directly after the last displayed character.
printf("Your Number is %d\n",Number);