CariDotMy

 Forgot password?
 Register

ADVERTISEMENT

12Next
Return to list New
View: 8371|Reply: 26

tolong coding java atau c++....

[Copy link]
Post time 21-2-2010 10:53 PM | Show all posts |Read mode
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....
Reply

Use magic Report


ADVERTISEMENT


Post time 22-2-2010 02:35 PM | Show all posts
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
Reply

Use magic Report

Post time 1-3-2010 12:48 AM | Show all posts
#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...
Reply

Use magic Report

Post time 9-3-2010 04:16 PM | Show all posts
aku lecturer C++.. hehehe
Reply

Use magic Report

Post time 9-3-2010 07:55 PM | Show all posts
aku lecturer C++.. hehehe
kiki009 Post at 9-3-2010 16:16


aku bekas pelajar repeat paper C++.. hehehe
Reply

Use magic Report

Post time 12-3-2010 12:53 AM | Show all posts
aku ex-student yg dpt gred A dlm subjek C++.
he he he
Reply

Use magic Report

Follow Us
Post time 15-3-2010 06:07 PM | Show all posts
aku ialah C++..
Reply

Use magic Report

Post time 16-3-2010 03:51 PM | Show all posts
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";
}
Reply

Use magic Report


ADVERTISEMENT


Post time 16-3-2010 04:24 PM | Show all posts
#include <iostream>
using namespace std;

void JantanAtauBetina()
{
     char gender;
     
     cin >> gender;
     if (gender == 'M' || gender == 'm')
     {
                system ("cls");
                cout << "You are Male.";
                cout << endl;
                }
                else if (gender == 'F' || gender == 'f')
                {
                     system ("cls");
                     cout << "You are Female.";
                     cout << endl;
                     }
                     else
                     {
                         system ("cls");
                         cout << "No Answer.";
                         cout << endl;
                         }
}

int main ()
{
    system ("title Identity crisis");
   
    cout << "Enter your gender (M-male, F-female): ";
    JantanAtauBetina();
   
    system("pause");
    return (0);
}

Reply

Use magic Report

Post time 16-3-2010 04:36 PM | Show all posts
erk...aku pon dah lupa pasal return(0) ngan system( " pause " ) tuh...huhu...kalo xpause memang xnmpk la "you are male or female"..ekeke.
Reply

Use magic Report

Post time 17-3-2010 11:46 PM | Show all posts
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.
Reply

Use magic Report

Post time 18-3-2010 08:46 AM | Show all posts
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 ...
otai_g Post at 17-3-2010 23:46


wah....betul2...nih baru dapat refresh sket peninggalan C++ aku...hu...dah bertahun2 xsentuh C++. Skrg dok guna VB.Net ngan C# ...tq otai_g tolong aku refresh balek C++ nih...   
moral of the story, ada ilmu kena amalkan.
Reply

Use magic Report

Post time 19-3-2010 01:25 AM | Show all posts
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
Reply

Use magic Report

Post time 22-3-2010 08:18 PM | Show all posts
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
Reply

Use magic Report

Post time 22-3-2010 08:23 PM | Show all posts
oo..lupe nk gtaw..sy gune header file <iostream.h>
Reply

Use magic Report

Post time 23-3-2010 10:47 AM | Show all posts
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

  1. charge = 0   <<initialize charge duit..awal2 kena 0
  2. tempMile = <input dari user> <<amek input letak kat temporary variable

  3. if (tempMile <= 100 && tempMile >0)    << kalo tempMile tuh x exceed 100 and lebih pada 0
  4. {
  5. charge = charge + 0.25;
  6. <sini display charge>
  7. }
  8. else if (tempMile>100)  <<nih kalo exceed
  9. {
  10.   charge = charge + 0.25       <<first 100 mile memang kena 0.25
  11.   tempMile = tempMile - 100    <<pastuh tolak 100 mile yg awal2 tuh sbb dah kena charge..

  12.   while(tempMile<0)            <<sini loop check slagi mile tuh masih ada value +ve
  13.   {
  14.      charge = charge + 0.15     <<tmbah charge additional tu
  15.      tempMile = tempMile - 100  <<pastu tolak mile
  16.   }

  17.   <sini display charge>
  18. }
  19. else
  20. {
  21.    <sini letak ler aper2 since user tuh input -ve value...kot2 la dia mangkuk sangat nk letak -ve kat mile tuh>
  22. }
Copy the Code
Reply

Use magic Report


ADVERTISEMENT


Post time 23-3-2010 11:49 AM | Show all posts
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;
        

}
Reply

Use magic Report

Post time 23-3-2010 02:10 PM | Show all posts
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..

  1. if (mile<= 100 && mile>0)
  2. {
  3.    total_price = mile*0.25;
  4. cout<<"The total price is "<<total_price<<endl;
  5. }
  6. else if(mile > 100)
  7. {
  8.    total_price = (100*0.25)+((mile-100)*0.15);
  9. cout<<"The total price is "<<total_price<<endl;
  10. }
  11. else
  12. {
  13. cout<< "Invalid input!"<<endl;
  14. }
Copy the Code
Reply

Use magic Report

Post time 23-3-2010 02:21 PM | Show all posts
kalo nk wat guna loop leh gak:
  1. double total_price, mile;
  2. int counter;
  3. counter = 0


  4. if(mile>0)
  5. {
  6.   
  7.   while(mile>0)
  8. {
  9.   if(counter <= 100)
  10.   {
  11.     total_price = total_price + 0.25;
  12.     counter = counter + 1;
  13.     mile = mile - 1;
  14.   }
  15.   else
  16.   {
  17.     total_price = total_price + 0.15;
  18.     mile = mile - 1;
  19.   }
  20. }
  21. }
  22. else
  23. {
  24. cout<< "Invalid input!"<<endl;
  25. }
Copy the Code
Reply

Use magic Report

Post time 9-5-2010 12:13 PM | Show all posts
salam...leh explain x tntg law beta cmne tp law char tawla
Reply

Use magic Report

12Next
Return to list New
You have to log in before you can reply Login | Register

Points Rules

 

ADVERTISEMENT



 

ADVERTISEMENT


 


ADVERTISEMENT
Follow Us

ADVERTISEMENT


Mobile|Archiver|Mobile*default|About Us|CariDotMy

8-1-2025 11:51 AM GMT+8 , Processed in 0.479858 second(s), 32 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

Quick Reply To Top Return to the list