עזרה

BlackHat

New member
עזרה

אני מריץ את התוכנית הבאה:
#include <stdio.h> int main() /* this is the main function*/ { int tmpsc; printf("hello world\n"); printf("this is my first program in c\n"); scanf("&d", &tmpsc); printf("%d\n", tmpsc); }​
וברגע שאני מקיש על 5 או כל דבר אחר זה פולט לי רצף של מספרים מישהו יכול להסביר לי מה הבעייה פה ולמה הוא לא פולט לי את 5?! או כל מספר אחר שאני בוחר.
 

therebel

New member
re

try scanf("%d", &tmpsc); instead
 

gst

New member
שגיאת scanf

זה צריך להיות scanf("%d", &tmpsc);d ולא scanf("&d", &tmpsc); כמו שכתבת
 

BlackHat

New member
תודה ומה לא בסדר עם זה ....

#include <stdio.h> int main() /* this is the main function*/ { float num; int x, y; printf("want to your everage grades?\n"); printf("please enter two numbers: \n"); scanf("%d %d", &x, &y); num = (x+y) / 2.0; printf("%d/n", num); }​
 

IdanR

New member
יכול להיות שתצטרך שם..

typecast כלומר: num = (float)(x+y) / 2 וכשאתה מדפיס, הייתי ממליץ על
printf("%.2d\n");​
כדי שידפיס רק שתי ספרות אחרי הנקודה. אגב, למען הדיוק, הייתי רוצה לתקן את המשפט הראשון באנגלית.. Want the avarage of your grades?
 

IdanR

New member
אה, כמובן..

אתה מנסה להדפיס מספר שלם, ואילו זה משתנה מסוג float. הנה:
printf("%.2f\n", num);​
מקווה שעזרתי.
 
למעלה