Bunu yeni yaptım. goto'yu kullandım. Ama diğerlerini öğrenince(while, for...) onları kullanacağım.
#include<stdio.h>
int main( void )
{
float a, b, c, d;
char o_i[50], o_s[50];
u:
printf("Ogrencinin Ismi Soyismi\n");
printf("Ogrencinin ismi:");
scanf("%s", o_i);
printf("Ogrencinin soyismi:");
scanf("%s", o_s);
printf("\n%s %s ogrencimizin 1. dönem not ortalamasi icin notlari girin:\n\n", o_i, o_s);
l:
printf("1. sinav notunu giriniz:");
scanf("%f", &a);
if( a<=15 )
printf("%s %s ogrencisinin %.2f almis oldugu not cok kotu.\n\n", o_i, o_s, a);
else if(a>=15 && a<45)
printf("%s %s ogrencisinin %.2f almis oldugu not kotu.\n\n",o_i, o_s, a);
else if(a>=45 && a<70)
printf("%s %s ogrencisinin %.2f almis oldugu not orta.\n\n",o_i, o_s, a);
else if(a>=70 && a<85)
printf("%s %s ogren,,cisinin %.2f almis oldugu not ıyı.\n\n",o_i, o_s, a);
else if(a>=85 && a<=100)
printf("%s %s ogrencisinin %.2f almis oldugu not cok ıyı.\n\n",o_i, o_s, a);
else
{printf("Girdiğiniz deger hatali.\n");
goto l;
}
k:
printf(" 2. sinav notunu giriniz:");
scanf("%f", &b);
if( b<=15 )
printf("%s %s ogrencisinin %.2f almis oldugu not cok kotu.\n\n", o_i, o_s, b);
else if(b>=15 && b<45)
printf("%s %s ogrencisinin %.2f almis oldugu not kotu.\n\n",o_i, o_s, b);
else if(b>=45 && b<70)
printf("%s %s ogrencisinin %.2f almis oldugu not orta.\n\n",o_i, o_s, b);
else if(b>=70 && b<85)
printf("%s %s ogrencisinin %.2f almis oldugu not ıyı.\n\n",o_i, o_s, b);
else if(b>=85 && b<=100)
printf("%s %s ogrencisinin %.2f almis oldugu not cok ıyı.\n\n",o_i, o_s, b);
else
{printf("Girdiğiniz deger hatali.\n");
goto k;
}
m:
printf("3. sinav notunu giriniz:");
scanf("%f", &c);
if( c<=15 )
printf("%s %s ogrencisinin %.2f almis oldugu not cok kotu.\n\n", o_i, o_s, c);
else if(c>=15 && c<45)
printf("%s %s ogrencisinin %.2f almis oldugu not kotu.\n\n",o_i, o_s, c);
else if(c>=45 && c<70)
printf("%s %s ogrencisinin %.2f almis oldugu not orta.\n\n",o_i, o_s, c);
else if(c>=70 && c<85)
printf("%s %s ogrencisinin %.2f almis oldugu not ıyı.\n\n",o_i, o_s, c);
else if(c>=85 && c<=100)
printf("%s %s ogrencisinin %.2f almis oldugu not cok ıyı.\n\n",o_i, o_s, c);
else
{printf("Girdiğiniz deger hatali.\n");
goto m;
}
d = (a + b + c) / 3;
printf("%s %s ogrencisinin 1. donem ortalamasi: %.2f\n\n",o_i, o_s, d);
if( d<=15 )
printf("%s %s ogrencisinin %.2f almis oldugu not cok kotu.\n\n", o_i, o_s, d);
else if(d>=15 && d<45)
printf("%s %s ogrencisinin %.2f almis oldugu not kotu.\n\n",o_i, o_s, d);
else if(d>=45 && d<70)
printf("%s %s ogrencisinin %.2f almis oldugu not orta.\n\n",o_i, o_s, d);
else if(d>=70 && d<85)
printf("%s %s ogrencisinin %.2f almis oldugu not ıyı.\n\n",o_i, o_s, d);
else if(d>=85 && d<=100)
printf("%s %s ogrencisinin %.2f almis oldugu not cok ıyı.\n\n",o_i, o_s, d);
goto u;
return 0;
}
çalışma için çok teşkkr ederiz.
Float değerine girince harf girince program sorun veriyor. char a sayı girince hata vermiyor. Her iki durumda uyarı nasıl gerçekleştirilebilir.
Alıntı yapılan: 007 - 05 Ekim 2018 - 19:39:48
Bunu yeni yaptım. goto'yu kullandım. Ama diğerlerini öğrenince(while, for...) onları kullanacağım.
#include<stdio.h>
int main( void )
{
float a, b, c, d;
char o_i[50], o_s[50];
u:
printf("Ogrencinin Ismi Soyismi\n");
printf("Ogrencinin ismi:");
scanf("%s", o_i);
printf("Ogrencinin soyismi:");
scanf("%s", o_s);
printf("\n%s %s ogrencimizin 1. dönem not ortalamasi icin notlari girin:\n\n", o_i, o_s);
l:
printf("1. sinav notunu giriniz:");
scanf("%f", &a);
if( a<=15 )
printf("%s %s ogrencisinin %.2f almis oldugu not cok kotu.\n\n", o_i, o_s, a);
else if(a>=15 && a<45)
printf("%s %s ogrencisinin %.2f almis oldugu not kotu.\n\n",o_i, o_s, a);
else if(a>=45 && a<70)
printf("%s %s ogrencisinin %.2f almis oldugu not orta.\n\n",o_i, o_s, a);
else if(a>=70 && a<85)
printf("%s %s ogren,,cisinin %.2f almis oldugu not ıyı.\n\n",o_i, o_s, a);
else if(a>=85 && a<=100)
printf("%s %s ogrencisinin %.2f almis oldugu not cok ıyı.\n\n",o_i, o_s, a);
else
{printf("Girdiğiniz deger hatali.\n");
goto l;
}
k:
printf(" 2. sinav notunu giriniz:");
scanf("%f", &b);
if( b<=15 )
printf("%s %s ogrencisinin %.2f almis oldugu not cok kotu.\n\n", o_i, o_s, b);
else if(b>=15 && b<45)
printf("%s %s ogrencisinin %.2f almis oldugu not kotu.\n\n",o_i, o_s, b);
else if(b>=45 && b<70)
printf("%s %s ogrencisinin %.2f almis oldugu not orta.\n\n",o_i, o_s, b);
else if(b>=70 && b<85)
printf("%s %s ogrencisinin %.2f almis oldugu not ıyı.\n\n",o_i, o_s, b);
else if(b>=85 && b<=100)
printf("%s %s ogrencisinin %.2f almis oldugu not cok ıyı.\n\n",o_i, o_s, b);
else
{printf("Girdiğiniz deger hatali.\n");
goto k;
}
m:
printf("3. sinav notunu giriniz:");
scanf("%f", &c);
if( c<=15 )
printf("%s %s ogrencisinin %.2f almis oldugu not cok kotu.\n\n", o_i, o_s, c);
else if(c>=15 && c<45)
printf("%s %s ogrencisinin %.2f almis oldugu not kotu.\n\n",o_i, o_s, c);
else if(c>=45 && c<70)
printf("%s %s ogrencisinin %.2f almis oldugu not orta.\n\n",o_i, o_s, c);
else if(c>=70 && c<85)
printf("%s %s ogrencisinin %.2f almis oldugu not ıyı.\n\n",o_i, o_s, c);
else if(c>=85 && c<=100)
printf("%s %s ogrencisinin %.2f almis oldugu not cok ıyı.\n\n",o_i, o_s, c);
else
{printf("Girdiğiniz deger hatali.\n");
goto m;
}
d = (a + b + c) / 3;
printf("%s %s ogrencisinin 1. donem ortalamasi: %.2f\n\n",o_i, o_s, d);
if( d<=15 )
printf("%s %s ogrencisinin %.2f almis oldugu not cok kotu.\n\n", o_i, o_s, d);
else if(d>=15 && d<45)
printf("%s %s ogrencisinin %.2f almis oldugu not kotu.\n\n",o_i, o_s, d);
else if(d>=45 && d<70)
printf("%s %s ogrencisinin %.2f almis oldugu not orta.\n\n",o_i, o_s, d);
else if(d>=70 && d<85)
printf("%s %s ogrencisinin %.2f almis oldugu not ıyı.\n\n",o_i, o_s, d);
else if(d>=85 && d<=100)
printf("%s %s ogrencisinin %.2f almis oldugu not cok ıyı.\n\n",o_i, o_s, d);
goto u;
return 0;
}
Daha düzenli değişken isimleri kullanmanızı ve girdi bırakmanızı öneriyorum.(biraz içeriden başlatın if while gibi yapıları).
[mention=642108]@007[/mention]
Lütfen çıktıları ve kodları kod etiketleri içerisinde (http://forum.ubuntu-tr.net/index.php?topic=14283.0) paylaşın.
İletinizdeki çıktıları/kodları kod etiketi içerisine aldım.
[mention=642469]@007[/mention]
Char'a sayı girebilirsiniz normalde şöyle işler
char a;
a = 4;
Yes, you can store 8 bit integer value in char type variable.
Range of signed char is -128 to +127
and range of unsigned char is 0 to 255
8 bitlik bir integer tutabilirsiniz
eğer signed char olarak tanımlarsanız -128 den +127 ye kadar rangesi vardır
eğer unsigned char kullanırsanız "-" sayıları içerisinde barındıramazsınız ufak bir örnek;
char a = 5;
int b = 10;
printf("%d",a+b);
//Output; 15
Bu arada belki aklınıza %d ile nasıl çalışıyor o integer için değilmiydi sorusu takılabilir onunda cevabı;
Why %d works for char? Because when you pass chars and shorts to ... function argument, they are automatically converted to ints.
And printf is declared as printf(const char *, ...);.
goto yerine do while döngüsü kullanabilirsiniz. Örneğin öğrenvi ismi boş girilince veya q girilinde break ile döngüden çıkarsınız.
Hocam döngüler sayesinde programınızı daha kısa tutarak yazabilirsiniz. goto komutu ise daha çok BASIC (ve türevleri) gibi yapısal olmayan programlama dillerinde kullanılıyor. Bir de koşul ifadelerini yazarken;
if( a<=15 )
ve ardından;
else if(a>=15 && a<45)
şeklinde bir yapı kullanmışsınız. Koşullarda örneğin yukarıda girilmesi istenen a değişkeni <=15 koşulunu sağlamıyorsa, yani a, 15'e küçük eşit değilse zaten o bloğu atlayıp bir sonrakine geçecektir. Sizin tekrardan else if(a>=15 && a<45) şeklinde (kırmızı ile gösterdiğim) bir ek kontrole daha ihtiyacınız yok. Onun yerine;
if(a<=15)
ve ardından;
else if(a<45)
diyebilirsiniz. Ayrıca orada bir sorun daha var. Birinci koşulda 15'e eşit olma durumuna dahil etmişsiniz ama ikinci else if koşulunda da 15'e eşit olma durumunu kabul etmişsiniz. Yani kullanıcı 15 girerse şayet, o zaman hem ilk if bloğu, hem de ardından gelen else if bloğuna dahil olacak demek.
Lütfen paylaştığınız kodların yanına açıklama satırı eklemeyi unutmayalım, bu hem yeni başlayan arkadaşlar için hem de sizin ileride binlerce satırlık kodlama yaptığınız zaman daha kolay anlaşılması için önemli bir detay
İyi çalışmalar.