Toufas Δημοσ. 21 Οκτωβρίου 2003 Δημοσ. 21 Οκτωβρίου 2003 prepei na ftiaksoume ena programma pou ipologizei to kostos enos fototipikou mixanimatos analoga me tis selides. mexri stigmis exo ta eksis : >#include <stdio.h> main() { int pages; float result=0.0f; printf("Enter number of pages.\n"); scanf("%d", &pages); if (pages >=1001) result = pages * 2; else if (pages >=501) result = pages * 3; else if (pages >=201) result = pages * 4; else result = pages * 5; printf("The Price is: %fpounds\n" ,result); return 0; } to provlima mou einai oti thelei akrivia mono sta 2 dekadika psifia kai den ksero pos na to valo afto any help?
hayzel Δημοσ. 21 Οκτωβρίου 2003 Δημοσ. 21 Οκτωβρίου 2003 Enas eukolos tropos einai : result = floor(result * 100.0) / 100.0; opou to 100 gia dio dekadika psifia. filika hayzel
hayzel Δημοσ. 21 Οκτωβρίου 2003 Δημοσ. 21 Οκτωβρίου 2003 Kai kati allo: an theleis apla na to tiponei me dio dekadika simeia kai den theleis na xaseis tin akribh timi apo tin variable "result" tote : fprintf ( "The price is: %.2f pounds \n" , result ) ; filika hayzel
Toufas Δημοσ. 21 Οκτωβρίου 2003 Μέλος Δημοσ. 21 Οκτωβρίου 2003 to programma mou se final morfi >#include <stdio.h> int main() { int pages; //setting the variable in order to calculate the pages double result; //this is the value were the result will be returned from the calculations printf("Enter number of pages : "); //asking for user input scanf("%d", &pages); //getting the input from user if (pages >= 1001) result = pages * 0.02; else if (pages >= 501) result = pages * 0.03; else if (pages >= 201) result = pages * 0.04; else result = pages * 0.05; //calculate the price depending on user input printf("The Price is: %.2f pounds\n" , result); //printing results on screen return 0; } to prob tora einai oti i ergasia leei kai merika alampournezika 1: you must provide a printed copy of your analysis,design and test data 2: test data should include normal and boundary checking
Toufas Δημοσ. 21 Οκτωβρίου 2003 Μέλος Δημοσ. 21 Οκτωβρίου 2003 episis mporo na valo an mpei kapio lathos input na tou ksanazitisei na to grapsei?px an valei arnitiko arithmo i valei kapia leksi
isim Δημοσ. 29 Οκτωβρίου 2003 Δημοσ. 29 Οκτωβρίου 2003 ap'oti fenetai den exeis ksanakanei C h kapoia alli glossa.... ta "alampournezika" pou sou zitaei einai to tipiko meros tis ipothesis. Aplos prepei na grapseis kapoio testing gia to programmataki sou to boundary checking einai na koitas an oi times sta oria pou elegxeis me to if statement sou dinei ta anamenomena apotelesmata. Ipotheto oti ksereis na sxediaseis auto pou egrapses opote den tha asxoleitho me to design. Telos mporeis na elenkseis to user input me ena if statement px if (pages>0) { if (pages >= 1001) result = pages * 0.02; else if (pages >= 501) result = pages * 0.03; else if (pages >= 201) result = pages * 0.04; else result = pages * 0.05; } else { printf("minima lathous",\n); }
sermojohn Δημοσ. 18 Δεκεμβρίου 2003 Δημοσ. 18 Δεκεμβρίου 2003 den kserw akribws pws grafetai stin c alla stin java yparxei mia domi epalipsis tou typou do{ } while(); etsi an dwsei arnitiko se bazei na ksanadwseis arithmo selidwn... meta tin while(); tha valeis na typenei to kostos elpizw na boithisa estw kai me tin xrisi allis glwssas...
philippas Δημοσ. 18 Δεκεμβρίου 2003 Δημοσ. 18 Δεκεμβρίου 2003 i scanf() den kanei giauto to programa. An o xristis patisi xaraktires pou den einai arithmoi i scanf tha tous metatrepsei se int pu einai lathos. Prepei prota na koitakseis an oi xaraktires pou vazei o xristis einai valid int elegxontas kathe xaraktira pou vazei o xristis. p.x an o xristis valei :100DDGGG, prepei na koitakseis an olloi oi xaraktires einai arithmoi kai einai na metatrepseis to input se int. O parakato kodikas kanei auto pou thes: >#include <stdio.h> #include <ctype.h> //use the function isdigit(*char) #include <stdlib.h> //use the function atoi(*char) int main() { //setting the variable in order to calculate the pages int pages=0; //this is the value were the result will be returned from the calculations float result=0.0; //store up to a 10-digit (int max=32767) and add a character to check the input char input[6]=""; int i=0; // used in the loop to test for digits. printf("Enter number of pages : "); //asking for user input gets(input); // get the input and srore it in a char[6] //check if entered a number with more than 5 digits if(input[5]!='\0') { printf("The input you entered is not valid"); getchar(); return 0; } //test for digits in the string entered by the user while(input[i]!='\0') { if(! isdigit(input[i])) //if the char is not a digit { printf("The input you entered is not valid"); getchar(); // wait until the user presses return return 0; //exit program } i++; } pages = atoi(input);// convert the valid chars to an int number if (pages > 1000) result = pages * 0.02; else if (pages > 500) result = pages * 0.03; else if (pages > 200) result = pages * 0.04; else result = pages * 0.05; //calculate the price depending on user input printf("pages:%d\n\n",pages); printf("The Price is: %.2f pounds\n" , result); //printing results on screen getchar(); return 0; } To mono pou den kanei einai na kanei check gia overflow otan o user valei enan arithmo metaksi tou 32767 kai tou 99999. Prepei na kaneis auto ton elegxo an metatrepseis prota to input se mia metavliti megaliteri tou int kai meta na kaneis check if(x>32767 && x<99999) printf("Invalid input"); Afou omos den mporoun oi selides na paroun arnitiko arithmo, kalo einai na xrisimopoiseis unsigned metavlites.
Προτεινόμενες αναρτήσεις
Αρχειοθετημένο
Αυτό το θέμα έχει αρχειοθετηθεί και είναι κλειστό για περαιτέρω απαντήσεις.