Forum Sementara Putera.com

Would you like to react to this message? Create an account in a few clicks or log in to continue.
Forum Sementara Putera.com

Bersama kita perkemaskan forum ini sementara forum asal dalam pemulihan.

Forum putera dah kembali. Masalah sudah berjaya diselesaikan. Sila lawati http://forum.putera.com/tanya


3 posters

    Tentang soalan C++

    azri90
    azri90
    Ahli Baharu
    Ahli Baharu


    Gender : Male Number of posts : 88
    Location : Subang
    Job/hobbies : Sakat adik techik pempuan aku
    Registration date : 03/03/2009

    Tentang soalan C++ Empty Tentang soalan C++

    Post by azri90 Fri Nov 27, 2009 1:16 am

    Salam...nie baru nak jinak2 dlm dunai aturcara nie...ok jadi soalannya...
    Libray aku ialah iostream..

    Macam mane nak tukar int kepada char??:Contohnya ada nombor 1-12 utk mewakili bulan..tetapi output dia mestila dalam huruf..
    Salah satu cara ialah mengunakan switch.

    Code:

    int month;
    cout<<"Please input current month:";
       
    cin>>month;
       
                    switch(month){
          case 1:cout<<"Month=January"<<endl;
             break;
          
          case 2:cout<<"Month=Febuary"<<endl;
             break;
          
          case 3:cout<<"Month=March"<<endl;
             break;
          
          case 4:cout<<"Month=April"<<endl;
             break;
          
          case 5:cout<<"Month=May"<<endl;
             break;
          
          case 6:cout<<"Month=Jun"<<endl;
             break;
          
          case 7:cout<<"Month=July"<<endl;
             break;
          
          case 8:cout<<"Month=August"<<endl;
             break;
          
          case 9:cout<<"Month=September"<<endl;
             break;
          
          case 10:cout<<"Month=October"<<endl;
             break;
          
          case 11:cout<<"Month=November"<<endl;
             break;
          
          case 12:cout<<"Month=December"<<endl;
             break;
          default:cout<<"ERROR"<<endl;
             break;
    }

    contoh la kalau output mcm nie,mcm mane nak buat??

    Code:
    int month;
    cout<<"Please input current month"<<endl;
    cin>>month
    //input adalah angka
    cout<<"This month is: "<<month<<;
    //output ini mestilah ditukar kepada huruf

    Ada caranye x??
    Itu saje soalan saye...
    TOYSЯUS
    TOYSЯUS
    Moderators
    Moderators


    Gender : Male Number of posts : 1571
    Age : 37
    Location : Kolam Kering - 3°5′00″N 101°32′00″E
    Job/hobbies : Pembunuh
    Registration date : 27/02/2009

    Tentang soalan C++ Empty Re: Tentang soalan C++

    Post by TOYSЯUS Fri Nov 27, 2009 1:50 am

    Sorry aku dah lama tak program.
    Jadi aku rasa macam ni boleh jugak kot:

    Code:
    int month;
    cout<<"Please input current month"<<endl;
    cin>>month;
    //input adalah angka
    cout<<"This month is:";

    if (month == 1) cout<<"January";
    else if (month == 2) cout<<"February";
    else if (month == 3) cout..............;
    else if (month......................;
    else cout<<"Error";


    Last edited by ??????????? on Mon Nov 30, 2009 10:04 am; edited 1 time in total (Reason for editing : oops typo kat line 2)
    neology
    neology
    Ahli Baharu
    Ahli Baharu


    Gender : Male Number of posts : 372
    Age : 38
    Registration date : 25/04/2009

    Tentang soalan C++ Empty Re: Tentang soalan C++

    Post by neology Sat Nov 28, 2009 10:32 pm

    ko try gune array..

    Code:

    char* bulan[12] = {"Error","January","February","March","April","May","June","July","August","September","October","November","December"};
    int month;

    cout<<"Please enter the month";
    cin>>month;

    cout<<"Month : "<<bulan[month]<<;

    *aku xsure syntax utk cout>> ni btol ke x..agak2 je ni..kalo salah..harap maaf Rolling Eyes
    azri90
    azri90
    Ahli Baharu
    Ahli Baharu


    Gender : Male Number of posts : 88
    Location : Subang
    Job/hobbies : Sakat adik techik pempuan aku
    Registration date : 03/03/2009

    Tentang soalan C++ Empty Re: Tentang soalan C++

    Post by azri90 Mon Nov 30, 2009 2:33 am

    HUhu...error la...maaf la...x pandai nak fix sendiri...ada satu error...dia kata too many intialize..
    Apa eh??
    TOYSЯUS
    TOYSЯUS
    Moderators
    Moderators


    Gender : Male Number of posts : 1571
    Age : 37
    Location : Kolam Kering - 3°5′00″N 101°32′00″E
    Job/hobbies : Pembunuh
    Registration date : 27/02/2009

    Tentang soalan C++ Empty Re: Tentang soalan C++

    Post by TOYSЯUS Mon Nov 30, 2009 10:06 am

    Boleh pastekan codingnya?

    Sponsored content


    Tentang soalan C++ Empty Re: Tentang soalan C++

    Post by Sponsored content


      Current date/time is Fri Mar 29, 2024 7:22 am