jordaninio Δημοσ. 30 Δεκεμβρίου 2011 Δημοσ. 30 Δεκεμβρίου 2011 γεια σας.εχω ξεκινησει να γραφω προγραμματακια στη c με το παραπανω προγραμμα.αυτο που δεν καταλαβαινω και μαλλον ειναι δικια μου παραλειψη..οταν κανω release και μετα παω να τρεξω το exe η μαυρη οθονη ερχεται και φευγει αμεσως χωρις να προλαβαινω να δω το προγραμμα και να κανω αυτα που θελω..ευχαριστω εκ των προτερων και συγγνωμη για την χαζη απορια αλλα τωρα ξεκιναω
Επισκέπτης Δημοσ. 30 Δεκεμβρίου 2011 Δημοσ. 30 Δεκεμβρίου 2011 Δοκίμασες να βάλεις: system("pause"); return 0; στο τέλος?
jordaninio Δημοσ. 30 Δεκεμβρίου 2011 Μέλος Δημοσ. 30 Δεκεμβρίου 2011 >#include<stdio.h> int main() { int arithmo1; int arithmo2; char praxi; printf ( "Parakalo pliktrologiste: +. gia prosthesi , -. gia afairesi , *. gia pollaplasiasmo , /. gia diairesi , ^. gia ton ipologismo tis dinamis , e. gia exodo apo to programma\n" ); praxi = getchar(); printf ("dose arithmo1\n"); scanf ("%d",&arithmo1); printf ("dose arithmo2\n"); scanf ("%d",&arithmo2); while (praxi != 'e' ) { if (praxi == '+' ) printf ("%d", prosthesi(arithmo1,arithmo2) ); else if (praxi=='-') printf("%d",afairesi(arithmo1,arithmo2) ); else if(praxi=='*') printf("%d",pollaplasiasmos(arithmo1,arithmo2)); else if(praxi=='/' && airthmo2!=0); printf("%d".diairesi(arithmo1,arithmo2)); else if(praxi=='^'); printf("%d",dinami(arithmo1,arithmo2)); printf ( "Parakalo pliktrologiste: +. gia prosthesi , -. gia afairesi , *. gia pollaplasiasmo , /. gia diairesi , ^. gia ton ipologismo tis dinamis , e. gia exodo apo to programma\n" ); praxi = getc(); } return 0; } int prosthesi(int arithmo1,int arithmo2 ); { return arithmo1+arithmo2 ; } int afairesi(int arithmo1,arithmo2); {return arithmo1-arithmo2 } int pollaplasiasmos(int arithmo1,arithmo2); {return arithmo1*arithmo2 } int diairesi(int arithmo1,int arithmo2); {return arithmo1/arithmo2 } int dinami(int arithmo1,int arithmo2); {for (int counter=1;counter<arithmo2;counter++);{ res=arithmo1*arithmo1} return res } ναι εχω βαλει..
migf1 Δημοσ. 30 Δεκεμβρίου 2011 Δημοσ. 30 Δεκεμβρίου 2011 Στον κώδικα που δίνεις δεν βλέπω να έχεις βάλει: system("pause"); πριν τερματίσεις την main() με return 0;
jordaninio Δημοσ. 30 Δεκεμβρίου 2011 Μέλος Δημοσ. 30 Δεκεμβρίου 2011 φιλε το βαζω πριν το return και μου βγαζει error C3861: 'system': identifier not found εδιτ:ηθελε και #include <process.h>..το βρηκα..ευχαριστώ!!
migf1 Δημοσ. 30 Δεκεμβρίου 2011 Δημοσ. 30 Δεκεμβρίου 2011 Δοκίμασε με: #include <stdlib.h> αν και ο κώδικάς σου υποφέρει έτσι κι αλλιώς από σκουπίδια στο stdin λόγω της: getc(); Αντί για getc() όρισε ένα μεγάλο c-string, π.χ. > char input[ 255+1] = {'\0'}; και διάβαζε αυτό από τη stdin με fgets() και κατόπιν κράτα μονάχα τον 1ο χαρακτήρα του για την πράξη... > fgets( input, 255+1, stdin); praxi = input[0]; > int main( void ) { char input[255+1] = {'\0'}; int arithmo1; int arithmo2; char praxi; printf ( "Parakalo pliktrologiste: +. gia prosthesi , -. gia afairesi , *. gia pollaplasiasmo , /. gia diairesi , ^. gia ton ipologismo tis dinamis , e. gia exodo apo to programma\n" ); fgets(input, 255+1, stdin); praxi = input[0]; ... while (praxi != 'e' ) { ... printf ( "Parakalo pliktrologiste: +. gia prosthesi , -. gia afairesi , *. gia pollaplasiasmo , /. gia diairesi , ^. gia ton ipologismo tis dinamis , e. gia exodo apo to programma\n" ); fgets(input, 255+1, stdin); praxi = input[0]; } return 0; } EDIT: Βασικά ο κώδικας είναι γεμάτος από συντακτικά λάθη, τα οποία και στα έφτιαξα ώστε τουλάχιστον να γίνεται compile και να μπορέσεις να προχωρήσεις με το πρόγραμμα (π.χ. να βάλεις αλλαγές γραμμής στο output, να τσεκάρεις να μην είναι 0 ο παρανομαστής όταν κάνεις διαίρεση, να βάλεις do-while λούπα αντί για while για να μην διπλογράφεις κώδικα, κλπ). Επίσης στον έφτιαξα ώστε να είναι στοιχισμένος κι ευανάγνωστος, ώστε να μάθεις να γράφεις ευανάγνωστο κώδικα από τώρα που είσαι ακόμα στην αρχή. Τα κενά διαστήματα και οι κενές γραμμές είναι φίλοι σου! Ο compiler τα σβήνει έτσι κι αλλιώς, οπότε δεν έχεις απολύτως κανένα λόγο να τα τσιγκουνεύεσαι (χωρίς να το παρακάνεις κιόλας). Είναι επίσης ΕΥΕΡΓΕΤΙΚΟ όταν προσπαθείς να βρεις λάθη! Επίσης, για απλά προγράμματα ρύθμισε το Tab στις 8 θέσεις, ενώ για πιο σύνθετα στις 4 θέσεις. Εγώ τον έκανα με 8... > #include <stdio.h> #include <stdlib.h> /* Function Prototypes */ int prosthesi( int, int ); int afairesi( int, int ); int pollaplasiasmos( int, int ); int diairesi( int, int ); int dinami( int, int ); /* ------------------------------------------------ */ int main( void ) { char input[255+1] = {'\0'}; int arithmo1; int arithmo2; char praxi; printf( "Parakalo pliktrologiste: +. gia prosthesi , -. gia afairesi , *. gia pollaplasiasmo , /. gia diairesi , ^. gia ton ipologismo tis dinamis , e. gia exodo apo to programma\n" ); fgets( input, 255+1, stdin ); praxi = input[0]; printf( "dose arithmo1\n" ); scanf( "%d", &arithmo1 ); printf( "dose arithmo2\n" ); scanf( "%d", &arithmo2 ); while ( praxi != 'e' ) { if ( praxi == '+' ) printf ("%d", prosthesi(arithmo1, arithmo2) ); else if ( praxi=='-' ) printf("%d", afairesi(arithmo1, arithmo2) ); else if ( praxi == '*' ) printf("%d", pollaplasiasmos(arithmo1, arithmo2) ); else if ( praxi == '/' && arithmo2 != 0 ) printf("%d", diairesi(arithmo1, arithmo2) ); else if ( praxi == '^') printf("%d",dinami(arithmo1, arithmo2) ); printf( "Parakalo pliktrologiste: +. gia prosthesi , -. gia afairesi , *. gia pollaplasiasmo , /. gia diairesi , ^. gia ton ipologismo tis dinamis , e. gia exodo apo to programma\n" ); fgets( input, 255+1, stdin ); praxi = input[0]; } return 0; } /* ------------------------------------------------ */ int prosthesi( int arithmo1, int arithmo2 ) { return arithmo1 + arithmo2; } /* ------------------------------------------------ */ int afairesi( int arithmo1, int arithmo2 ) { return arithmo1 - arithmo2; } /* ------------------------------------------------ */ int pollaplasiasmos( int arithmo1, int arithmo2 ) { return arithmo1 * arithmo2; } /* ------------------------------------------------ */ int diairesi( int arithmo1, int arithmo2 ) { return arithmo1 / arithmo2; } /* ------------------------------------------------ */ int dinami( int arithmo1, int arithmo2 ) { int res = 0; for (int counter=1; counter < arithmo2; counter++) res = arithmo1 * arithmo1; return res; }
migf1 Δημοσ. 30 Δεκεμβρίου 2011 Δημοσ. 30 Δεκεμβρίου 2011 Πριν την κάνω κι εγώ για σπιτάκι μου σιγά-σιγά, δες μια λίγο πιο προχωρημένη προσέγγιση του κώδικά σου, που δουλεύει και με πραγματικούς αριθμούς εκτός από ακέραιους. Btw, αν είναι άσκηση για σχολή/σχολείο και την παραδώσεις έτσι, τότε το πλέον πιθανό είναι να στην μηδενίσει ως μη δική σου > #include <stdio.h> /* for puts(), printf(), fgets() */ #include <stdlib.h> /* for atof() */ #include <string.h> /* for strchr() */ #include <math.h> /* for fabs() */ #define MAXINPUT (255+1) /* max chars for our input line */ #define IS_FZERO(f) ( fabs(f) < 0.000000001 ) /* conditional for float zero */ #define IS_MNOPTION(c) ( strchr("e+-*/^", (c)) ) /* conditional for menu options */ enum ErrId { ERR_NOERROR = 0, ERR_DIV0 }; /* our error codes */ /* Function Prototypes */ char input_char( const char *prompt ); float input_float( const char *prompt ); double add( const float, const float ); double sub( const float, const float ); double mul( const float, const float ); double dvs( const float, const float, enum ErrId *error ); double pwr( const float, const float, enum ErrId *error ); /* -------------------------------------------------------------------- */ int main( void ) { float num1 = 0.0, num2 = 0.0; double res = 0.0; char op = '\0'; char *menu = { "\nΠαρακαλώ επιλέξτε:\n\t+ για πρόσθεση\n\t- για αφαίρεση\n\t* για πολλαπλασιασμό\n\t/ για διαίρεση\n\t^ για δύναμη\n\te για Έξοδο από το πρόγραμμα\n\t" }; for (; /* start infinite loop */ { enum ErrId error = ERR_NOERROR; op = input_char( menu ); if ( op == 'e' ) break; /* ... break out of the loop */ if ( !IS_MNOPTION(op) ) continue; /* ... skip current iteration */ num1 = input_float( "\nΔώστε 1ο αριθμό: " ); num2 = input_float( "Δώστε 2ο αριθμό: " ); if ( op == '+' ) res = add( num1, num2 ); else if ( op == '-' ) res = sub( num1, num2 ); else if ( op == '*' ) res = mul( num1, num2 ); else if ( op == '/') res = dvs( num1, num2, &error ); else if ( op == '^') res = pwr( num1, num2, &error ); printf( "\nΑποτέλεσμα: \t%g%s\n", res, error == ERR_NOERROR ? " " : "\b ERROR!" ); } /* for (; */ return 0; } /* -------------------------------------------------------------------- */ char input_char( const char *prompt ) { char input[MAXINPUT] = {'\0'}; if ( prompt ) printf("%s", prompt); return !fgets(input, MAXINPUT, stdin) ? '\0' : *input; } /* -------------------------------------------------------------------- */ float input_float( const char *prompt ) { char input[MAXINPUT] = {'\0'}; if ( prompt ) printf("%s", prompt); return !fgets(input, MAXINPUT, stdin) ? 0 : atof(input); } /* -------------------------------------------------------------------- */ double add( const float num1, const float num2 ) { return num1 + num2; } /* -------------------------------------------------------------------- */ double sub( const float num1, const float num2 ) { return num1 - num2; } /* -------------------------------------------------------------------- */ double mul( const float num1, const float num2 ) { return num1 * num2; } /* -------------------------------------------------------------------- */ double dvs( const float num1, const float num2, enum ErrId *error ) { return !IS_FZERO(num2) ? num1 / num2 : (float)(*error = ERR_DIV0); } /* -------------------------------------------------------------------- * Does NOT handle special cases, like when both base & exponential are negative */ double pwr( const float base, const float exp, enum ErrId *error ) { double ret = base; float temp = fabs(exp); if ( IS_FZERO(exp) ) return 1; if ( IS_FZERO(base) && exp < 0.0 ) return (double)(*error = ERR_DIV0); while ( --temp > 0.0 ) ret *= base; return exp > 0.0 ? ret : 1.0 / ret; }
παπι Δημοσ. 31 Δεκεμβρίου 2011 Δημοσ. 31 Δεκεμβρίου 2011 Btw το να σου κλεινει αμεσως ειναι σωστο. Βλεπεις η console τρεχει σε console και οχι σε windows. Μπορεις να φτιαξεις ενα ωραιοτατο script με ονομα ForWindows, ενα *.bat αρχειο που θα περιεχει ForWindows.bat > @echo off MyProgramName pause
Προτεινόμενες αναρτήσεις
Δημιουργήστε ένα λογαριασμό ή συνδεθείτε για να σχολιάσετε
Πρέπει να είστε μέλος για να αφήσετε σχόλιο
Δημιουργία λογαριασμού
Εγγραφείτε με νέο λογαριασμό στην κοινότητα μας. Είναι πανεύκολο!
Δημιουργία νέου λογαριασμούΣύνδεση
Έχετε ήδη λογαριασμό; Συνδεθείτε εδώ.
Συνδεθείτε τώρα