I’m new in C coding and I just wrote a C program, but when I tried to run the code, it gave a black screen. What do I need to change in my code to fix this problem?
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int islemler(){
int x,y,z,c,s0,s1,s2,s3;
printf("Merhaba, matematik islemlerine baslamak icinn lutfen ilk sayiyi giriniz...\n"); /*wants to first number*/
scanf("%d", &x);
printf("Simdi ise ikinci sayiyi giriniz...\n"); /*wants to second number*/
scanf("%d", &y);
printf("Son olarak 3. sayiyi giriniz...\n"); /*wants to thirth number*/
scanf("%d", &z);
printf("Yapacaginiz islemi secmek icin lutfen bir sayi seciniz...\n 1-----Toplama\n 2-----Cikarma\n 3-----Carpma\n 4-----Bolme"); /*Prompts the user to select an action. 1- addition 2- subtraction 3- multiplication 4- division*/
scanf("%d", &c);
s0= x+y+z;
s1= x-y-z;
s2= x*y*z;
s3= x/y/z;
if (c==1){
printf("Sonucunuz %d", s0); /*give answers*/
}
if (c==2){
printf("Sonucunuz %d", s1);
}
if (c==3){
printf("Sonucunuz %d", s2);
}
if (c==4){
printf("Sonucunuz %d", s3);
}
}
int main(){
int islemler();
return 0;
}
>Solution :
int main(){
int islemler();
return 0;
}
You basically declare islemler and then return. It does nothing. I think you wanted to call islemler and not declare it. Remove the int from that. Make it islemler():
int main() {
islemler();
return 0;
}
In your code, you’re declaring it. Which is basically like letting the compiler know that the function exists somewhere and not to worry. And it also helps to catch incorrect calls to functions. They are only required in certain situations when the compiler has no way to know that a function exist. If it occurs later on or if it is in a different compilation unit, it’s a good practice to declare the prototype like you have done. It does not call the function. And is also completely unnecessary here.
Also, the islemler function should return an int but doesn’t return anything. You should get a warning about this. Do not ignore warnings.