בנה את המחשבון !
אפשר לתכנת בכל שפה .
אין מגבלות מיוחדות .
חובה להעלות קוד מקור .
פרסים:
מקום ראשון:150 נקודות .
מקום שני:100 נקודות .
להגיש פה את המחשבונים שהכנתם .
בהצלחה
בנה את המחשבון !
אפשר לתכנת בכל שפה .
אין מגבלות מיוחדות .
חובה להעלות קוד מקור .
פרסים:
מקום ראשון:150 נקודות .
מקום שני:100 נקודות .
להגיש פה את המחשבונים שהכנתם .
בהצלחה
נערך לאחרונה על ידי lir the king; 10-12-2009 בשעה 21:47.
|
|
C++
קוד:#include <iostream.h> #include <conio.h> int mc(int x, int y) //Multiply two numbers { cout <<"\n\n"<< x <<" times "<< y <<" equals "; return (x*y); } int ac(int a, int b) //Add two numbers { cout <<"\n\n"<< a <<" plus "<< b <<" equals "; return (a+b); } int sc(int z, int c) //Subtract two numbers { cout <<"\n\n"<< z <<" minus "<< c <<" equals "; return (z-c); } int dc(int o, int t) //Divide two numbers { cout <<"\n\n"<< o <<" divided by "<< t <<" equals "; return (o/t); } void calc(char choice) { int on,tw,thr; if (choice == '+') //This whole block checks what the user wants to calculate, and refers to the proper routine to calculate it. { cout<<"You selected "<<choice<<". Please enter two numbers,\nsepperated by spaces,"; cout<<"that you want to add."<<endl;//print instructions for the user cin>>on;//Get the value of variable on cin>>tw;//Get the value of variable tw thr=ac(on,tw);//Get the sum of on and tw, and assign that value to thr cout<<thr<<"\n\n\n\aThanks for using my calculator!";//Print a thank you message } else if (choice =='-') { cout<<"You selected "<<choice<<". Please enter two numbers,\nsepperated by spaces, that you want to subtract."<<endl; cin>>on; cin>>tw; thr=sc(on,tw); cout<<thr<<"\n\n\n\aThanks for using my calculator!"; } else if (choice =='*') { cout<<"You selected "<<choice<<". Please enter two numbers,\nsepperated by spaces, that you want to multiply."<<endl; cin>>on; cin>>tw; thr=mc(on,tw); cout<<thr<<"\n\n\n\aThanks for using my calculator!"; } else if (choice =='/') { cout<<"You selected "<<choice<<". Please enter two numbers,\nsepperated by spaces, that you want to divide."<<endl; cin>>on; cin>>tw; thr=dc(on,tw); cout<<thr<<"\n\n\n\aThanks for using my calculator"; } else { cout<<"\nPlease reenter that value.\n\a"; cin>>choice; calc(choice,); } } void main() { clrscr(); int one, two, three; char choice; while (choice != 'e') { cout<<"\nPlease enter +,-,*, or / and then two numbers,\nsepperated by spaces, that you wish to\nadd,subtract,multiply,or divide.\nType e and press enter to exit."; cin>>choice; if (choice != 'e') { calc(choice); } } }
Two years he walks the earth. No phone, no pool, no pets, no cigarettes. Ultimate freedom. An extremist. An aesthetic voyager whose home is the road…Ten days and nights of freight trains and hitchhiking bring him to the Great White North. No longer to be poisoned by civilization he flees, and walks alone upon the land to become lost in the wild. - Alexander Supertramp May 1992
import java.util****anner;
public class calaulator
{
public static void main(String arg0[]) {
String a=null,b=null,c=null;
Scanner in = new Scanner(System.in);
String[] actions={"+","-","*","/"};
boolean again = true;
while (again) {
a=b=c=null;
System.out.println("WELCOME TO THE CALCULTOR");
System.out.println("------------------------");
while (a==null) {
System.out.println("Enter the first number..");
a=in.next();
try {
Double.parseDouble(a);
} catch (Exception e) {
System.out.println("PLEASE ENTER A NUMBER!!!");
a=null;
}
}
while (c==null) {
System.out.println("PLEASE ENTER THE ACTION YOU WOULD LIKE TO PREFORM: + , - , * , /");
c=in.next();
boolean temp=false;
for (String action: actions){
if (c.equals(action)) temp=true;
}
if (!temp) {
System.out.println("PLEASE ENTER ONE OF THE FOLLOWING ONLY! + , - , * , /");
c=null;
}
}
while (b==null) {
System.out.println("Enter the second number..");
b=in.next();
try {
Double.parseDouble(b);
} catch (Exception e) {
System.out.println("PLEASE ENTER A NUMBER!!!");
b=null;
}
}
double result=0;
if (c.equals("+")) {
result=Double.parseDouble(a)+Double.parseDouble(b);
System.out.println(""+a+"+"+b+"="+result);
}
else if (c.equals("-")) {
result=Double.parseDouble(a)-Double.parseDouble(b);
System.out.println(""+a+"-"+b+"="+result);
}
else if (c.equals("*")) {
result=Double.parseDouble(a)*Double.parseDouble(b);
System.out.println(""+a+"*"+b+"="+result);
}
else if (c.equals("/")) {
result=Double.parseDouble(a)/Double.parseDouble(b);
System.out.println(""+a+"/"+b+"="+result);
}
String strAgain="kldjs";
while ( (!strAgain.equalsIgnoreCase("y")) && (!strAgain.equalsIgnoreCase("n")) ) {
System.out.println("IT WAS VERY NICE TO MEET YOU, WOULD YOU LIKE ANOTHER CALCULATION? (y/n)?");
strAgain=in.next();
if ((!strAgain.equalsIgnoreCase("y")) && (!strAgain.equalsIgnoreCase("n"))) System.out.println("PLEASE ENTER ONLY y OR n");
}
if (!strAgain.equals("y")) {
again=false;
System.out.println("Good Bye");
}
}
}
}
תגיד איך + הערות לשיפור..
עשיתי מחשבון:
זה הקובץ sln:
http://www.f2h.co.il/5682744500227
תקמפל תדבג ותראה תמחשבון
נערך לאחרונה על ידי 2Moons; 19-12-2009 בשעה 20:00.
מצטער, האתגר נסגר הוא כבר לא המנהל.
תכירו את שמוליק, אבא קנה לי
הוא אוהב במבה, ביסלי ואת עודד מנשה
נכתב במקור על ידי אושרי