Jump to content
Sign in to follow this  
syira86

Bagaimana Nak Buat Coding Soalan C++ Nie

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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..

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
[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>;

Share this post


Link to post
Share on other sites
[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...

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...