syira86 2 Report post Posted September 22, 2011 salam ,sy masih baru dalam prgmming c++ nie, saya dapat soalan dari lect dan saya tak tahu bagaimana nak buat sebab nie invidual assgmnt..saya harap sgt abg2x n kak2x dpt tolong ajar saya..tq...ini soalan Write a [b]C++ [/b]Program to capture user input on FIRST number, SECOND number and OPERATOR which is either +, -, * or /, then using a [b]SWITCH..CASE[/b] programming construct to calculate the numbers based on the OPERATOR selected, an invalid user input, such as “p”, “1” or “=” will results an error message, such as “Unknown Operator!!” . The example output is shown as below:- Please enter FIRST number: 10 Please enter SECOND number: 5 Please enter OPERATOR [+, -, *, /] : * Result of 10 * 5 = 50 [b][size=4] [/size][/b] Quote Share this post Link to post Share on other sites
Zulhilmi Rahman 3 Report post Posted September 23, 2011 tak berapa igt la dari segi syntax.. #include <iostream.h> void main() { int no1,no2,opr; float jum; cout>>"Enter two number:\n"; cin<<no1<<no2; cout>>"Enter Operator: \n 1 - Plus(+),\n 2 - Minus(-),\n 3 - Multiple(*),\n 4 - Division(/)"; cin<<opr; switch (opr){ case '1': jum = no1+no2; break; case '2': jum = no1-no2; break; case '3': jum = no1*no2; break; case '4': jum = no1/no2; break; } cout<<"Jumlah = "<<jum; } try la kompil... ada error la kot.. tapi error syntax kot.. Quote Share this post Link to post Share on other sites
syira86 2 Report post Posted September 23, 2011 ok sy cuba ye..tima ksh ye Quote Share this post Link to post Share on other sites
Zulhilmi Rahman 3 Report post Posted September 23, 2011 owrite.. Quote Share this post Link to post Share on other sites
syira86 2 Report post Posted September 24, 2011 error nie Build started: Project: Assignment, Configuration: Debug Win32 ------ 1> assignment.cpp 1>c:\documents and settings\maluser01\desktop\assignment\assignment\assignment.cpp(3): fatal error C1083: Cannot open include file: 'iostream.h': No such file or directory ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== cmne nak fix Quote Share this post Link to post Share on other sites
Zulhilmi Rahman 3 Report post Posted September 30, 2011 cube tengok coding2 lain. camne dia punya include iostream.. Quote Share this post Link to post Share on other sites
akuccputsedut 147 Report post Posted September 30, 2011 [quote name='syira86' timestamp='1316854846' post='1072563'] error nie Build started: Project: Assignment, Configuration: Debug Win32 ------ 1> assignment.cpp 1>c:\documents and settings\maluser01\desktop\assignment\assignment\assignment.cpp(3): fatal error C1083: Cannot open include file: 'iostream.h': No such file or directory ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== cmne nak fix [/quote] nih nak create coding C ke C++... kalau C++ tak payah letak [b].h[/b] #include <iostream>; Quote Share this post Link to post Share on other sites
Zulhilmi Rahman 3 Report post Posted September 30, 2011 dia mention C++. tapi tak tau la.. da lupe la pulak. tak salah macam ada kene mengene ngan software masa blaja dulu. Quote Share this post Link to post Share on other sites
akuccputsedut 147 Report post Posted September 30, 2011 [quote name='Zulhilmi Rahman' timestamp='1317371152' post='1072889'] dia mention C++. tapi tak tau la.. da lupe la pulak. tak salah macam ada kene mengene ngan software masa blaja dulu. [/quote] yer laa tuh masalah software laa kot... rasanya arr... aku bukan pandai sangat pun... huhuhuhu... Quote Share this post Link to post Share on other sites
syira86 2 Report post Posted October 1, 2011 guna window visual express Quote Share this post Link to post Share on other sites
otai_g 3 Report post Posted November 10, 2011 nah. dah boring dah wat assignment2 mcm ni. [CODE]#include <iostream> using namespace std; void calc( double a, double b, char x ) { double T; switch (x) { case '+': T = a + b; break; case '-': T = a - b; break; case '*': T = a * b; break; case '/': T = a / b; break; } cout<<"Result of "<<a<<" "<<x<<" "<<b<<" = "<<T<<endl; } void main () { double fNum,sNum; char op; cout<<"Please enter FIRST number: "; cin>>fNum; cout<<"Please enter SECOND number: "; cin>>sNum; cout<<"Please enter OPERATOR [+, -, *, /] : "; cin>>op; calc( fNum, sNum, op ); }[/CODE] Quote Share this post Link to post Share on other sites