View: 8371|Reply: 26
|
tolong coding java atau c++....
[Copy link]
|
|
sape leh tolong cam ne nak wat pilihan dengan menggunakan statmen if...elsejika kita masokkan jantina 'F' ia akan kuar female dan 'm' ia akan kuar male....
kalu gune integer beta tau la nak wat....nie kene gune char....beta x tau la.... |
|
|
|
|
|
|
|
Post Last Edit by kambinggila at 22-2-2010 14:38
buat la if statement
if [ ${sex_opt} -eq 'F' || ${sex_opt} -eq 'f' then
echo 'Pompuan Lah!'
else
echo 'Lelaki ke?'
fi |
|
|
|
|
|
|
|
#include <iostream.h>
void main ()
{
char input;
cout<<"Masukkan jantina : ";
cin>>input;
if (input == 'm')
cout<<"Jantina lelaki";
if (input == 'f')
cout<<"Jantina perempuan";
else
cout<<"Tiada dlm database la mangkok";
}
ni aku buat secara life.
x tau ada error ke x sbb x de ms nak compile.
ko try jerk la.
hehehe... |
|
|
|
|
|
|
|
aku lecturer C++.. hehehe |
|
|
|
|
|
|
|
aku lecturer C++.. hehehe
kiki009 Post at 9-3-2010 16:16
aku bekas pelajar repeat paper C++.. hehehe |
|
|
|
|
|
|
|
aku ex-student yg dpt gred A dlm subjek C++.
he he he |
|
|
|
|
|
|
|
aku ialah C++.. |
|
|
|
|
|
|
|
aku dah lama tinggalkn c++ ..untuk menjawab persoalan TT, aku menyokong penuh jawapan otai_g.. nak lagi kemas letakkn curly braces untuk asingkan if ...else statement..nk lagi ok, includekan else if dlm coding tuh. contoh (otai_g, daku pau skit codingmu):
if (input == 'm')
cout<<"Jantina lelaki";
if (input == 'f')
cout<<"Jantina perempuan";
else
cout<<"Tiada dlm database la mangkok";
tukarkan kepada:
if (input == 'm')
{
cout<<"Jantina lelaki";
}
else if (input == 'f')
{
cout<<"Jantina perempuan";
}
else
{
cout<<"Tiada dlm database la mangkok";
} |
|
|
|
|
|
|
|
erk...aku pon dah lupa pasal return(0) ngan system( " pause " ) tuh...huhu...kalo xpause memang xnmpk la "you are male or female"..ekeke. |
|
|
|
|
|
|
|
10# FMKiller
aku cuba jwb ek.
maklum la aku pun dah lama tinggalkan c++ ni...
kalo salah tu sapa2 yg tau sila2 la betulkan..
return 0 tu kita gunakan dlm function sekiranya function tersebut x memulangkan apa2 nilai.
so kalo function tu ada memulangkan nilai, maka dia x leh guna return 0 sebaliknya kena guna return (something)
something adalah variable yg kita declare sama ada int ke, double ke, float ke or whatever..
tp kalo sesuatu function tu guna nama void automatik penggunaan return 0 terpaksa dimansuhkan sbb void tu sendiri membawa maksud kosong (tiada nilai yg dihantar).sbb tu dlm void main () tiada return 0.unless kalo kita guna int main (), so dihujung function main tu perlu dimasukkan return 0. |
|
|
|
|
|
|
|
12# FMKiller
tp syg keje yg aku tgh buat skang ni x memerlukan ilmu C++ yg aku ada.
kena cr ilmu lain plk.
kalo ada soalan coding C++ lg jgn la segan2 post kat sini.
rsnya dah lama kepala otak ni x diperah utk membuat coding2 yg mencabar |
|
|
|
|
|
|
|
Hai..sy new mber kat cny..sy kne wat esemen tok c++..sy da try wat tp xpat output y sepatutnye..sape2 kat cni y terer wat coding c++,,tlg la sy..buntu pale sy nyh..da la kene submit rabu ny.. soklan dy ceny:
the maju car rental company charges $0.25/mile if the total mileage does not exceeds 100. if the total mileage exceeds 100, the company charges $0.25/mile for the first 100 mile, then it charges $0.15 for any additional mileage over 100. write the program so that of the clerk enters the numbers of miles, the program would display the total price owed.
- ny gune if-else statement
-nak tyer..gune looping jgk x wat progrm ny sbb skg sy da msk bab looping.
tmksh byk2 sape y tlg..hehe |
|
|
|
|
|
|
|
oo..lupe nk gtaw..sy gune header file <iostream.h> |
|
|
|
|
|
|
|
Hai..sy new mber kat cny..sy kne wat esemen tok c++..sy da try wat tp xpat output y sepatutnye..sape2 kat cni y terer wat coding c++,,tlg la sy..buntu pale sy nyh..da la kene submit rabu ny.. soklan d ...
hamster91 Post at 22-3-2010 20:18
isk...awat xbuat thread sndri. hu..xper la..aku try tolong..tp aku letak pseudocode jer la..syntax C++ dah bnyk xigt..hehe
- charge = 0 <<initialize charge duit..awal2 kena 0
- tempMile = <input dari user> <<amek input letak kat temporary variable
- if (tempMile <= 100 && tempMile >0) << kalo tempMile tuh x exceed 100 and lebih pada 0
- {
- charge = charge + 0.25;
- <sini display charge>
- }
- else if (tempMile>100) <<nih kalo exceed
- {
- charge = charge + 0.25 <<first 100 mile memang kena 0.25
- tempMile = tempMile - 100 <<pastuh tolak 100 mile yg awal2 tuh sbb dah kena charge..
- while(tempMile<0) <<sini loop check slagi mile tuh masih ada value +ve
- {
- charge = charge + 0.15 <<tmbah charge additional tu
- tempMile = tempMile - 100 <<pastu tolak mile
- }
- <sini display charge>
- }
- else
- {
- <sini letak ler aper2 since user tuh input -ve value...kot2 la dia mangkuk sangat nk letak -ve kat mile tuh>
- }
Copy the Code |
|
|
|
|
|
|
|
ny contoh coding y sy try wat tok soklan sy y kat atas 2..tp ble kire gune clculator..jmlah x same ngn output y dikuakn program ..hope sape2 bole tlg..
#include <iostream.h>
void main ()
{
double mile, total_price ;
cout<< "Please enter the number of miles : "<<endl ;
cin >> mile ;
if (mile <= 100 ){
total_price = mile * 0.25;
}
else if(mile > 100 ){
total_price = (mile * 0.25) + ((mile - 100) * 0.15);
}
else{
cout<< "Invalid input!"<<endl;
}
cout<<"The total price is "<<total_price<<endl;
} |
|
|
|
|
|
|
|
ehhh... 0.25/mile...hahaha..xperasan ada per mile tuh..
kalo cmtuh senang jer la..xyah kira berapa kali 100 miles slepas first 100 mile tuh. huhu..
- if (mile<= 100 && mile>0)
- {
- total_price = mile*0.25;
- cout<<"The total price is "<<total_price<<endl;
- }
- else if(mile > 100)
- {
- total_price = (100*0.25)+((mile-100)*0.15);
- cout<<"The total price is "<<total_price<<endl;
- }
- else
- {
- cout<< "Invalid input!"<<endl;
- }
Copy the Code |
|
|
|
|
|
|
|
kalo nk wat guna loop leh gak:- double total_price, mile;
- int counter;
- counter = 0
- if(mile>0)
- {
-
- while(mile>0)
- {
- if(counter <= 100)
- {
- total_price = total_price + 0.25;
- counter = counter + 1;
- mile = mile - 1;
- }
- else
- {
- total_price = total_price + 0.15;
- mile = mile - 1;
- }
- }
- }
- else
- {
- cout<< "Invalid input!"<<endl;
- }
Copy the Code |
|
|
|
|
|
|
|
salam...leh explain x tntg law beta cmne tp law char tawla |
|
|
|
|
|
|
| |
|