שפת c
אני מנסה לעשות תוכנית פשוטה של מספר פעולות חישוב. זה הולך ככה: הכנס מספר 1 ->הכנס פעולת חשבון ->הכנס מספר 2 ->תנאי בשביל לדעת איזה פעולה הכניס המשתמש. עשיתי שורה בשביל לדעת איזה פעולה הכניס המשתמש, והקומפיילר לא רושם שיש בעיות ומריץ את התוכנית, אבל הוא מדלג על הקטע של הכנסת הפעולה והולך ישר להכניס את המספר השני. למה? הנה הקוד: #include <stdio.h> float a,b, tozaa; char action; float plus(float x, float y); float minus(float x, float y); float multip(float x, float y); float fraction(float x, float y); main () {//main printf("Enter a value to a\n"); scanf("%f", &a); // a value has been entered to a printf("select an action: + - * /"); scanf("%c", &action); //an action has been selected printf("\nEnter a value to b\n"); scanf("%f", &b); //a value has been entered to b switch(action) //determine which action has been chosen {//switch case '+': tozaa=plus(a,b); break; case '-': tozaa=minus(a,b); break; case '*': tozaa=multip(a,b); break; case '/': tozaa=fraction(a,b); break; default: printf("You have chosen a wrong action.\n"); }//end of switch }//end of main //Function plus float plus(float x, float y) { return(x+y); } //Function minus float minus(float x, float y) { return(x-y); } //Function multip float multip(float x, float y) { return(x*y); } //function fraction float fraction(float x, float y) { return(x/y); }
אני מנסה לעשות תוכנית פשוטה של מספר פעולות חישוב. זה הולך ככה: הכנס מספר 1 ->הכנס פעולת חשבון ->הכנס מספר 2 ->תנאי בשביל לדעת איזה פעולה הכניס המשתמש. עשיתי שורה בשביל לדעת איזה פעולה הכניס המשתמש, והקומפיילר לא רושם שיש בעיות ומריץ את התוכנית, אבל הוא מדלג על הקטע של הכנסת הפעולה והולך ישר להכניס את המספר השני. למה? הנה הקוד: #include <stdio.h> float a,b, tozaa; char action; float plus(float x, float y); float minus(float x, float y); float multip(float x, float y); float fraction(float x, float y); main () {//main printf("Enter a value to a\n"); scanf("%f", &a); // a value has been entered to a printf("select an action: + - * /"); scanf("%c", &action); //an action has been selected printf("\nEnter a value to b\n"); scanf("%f", &b); //a value has been entered to b switch(action) //determine which action has been chosen {//switch case '+': tozaa=plus(a,b); break; case '-': tozaa=minus(a,b); break; case '*': tozaa=multip(a,b); break; case '/': tozaa=fraction(a,b); break; default: printf("You have chosen a wrong action.\n"); }//end of switch }//end of main //Function plus float plus(float x, float y) { return(x+y); } //Function minus float minus(float x, float y) { return(x-y); } //Function multip float multip(float x, float y) { return(x*y); } //function fraction float fraction(float x, float y) { return(x/y); }