Thread: how to .. soft this problem

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    3

    how to .. soft this problem

    i have 1 problem there to run this program ...
    :
    #include<stdio.h>
    #include<conio.h>
    #define SABUN RM3.20
    #define SYAMPU RM14.90
    #define MAGGI RM2.70
    #define KICAP RM2.10
    #define SOS RM1.70
    #define SARDIN RM2.50
    #define UBAT GIGI RM4.50
    #define MILO RM8.90
    #define PEANUT BUTTER RM7.50
    #define ROTI RM1.90

    void main()
    {

    int pilih,jumlah;
    float harga;

    clrscr();
    printf("1.Sabun RM 3.20\n");
    printf("2.Syampu RM14.90\n");
    printf("3.Maggi RM 2.70\n");
    printf("4.KIcap RM 2.10\n");
    printf("5.Sos RM 1.70\n");
    printf("6.Sardin RM 2.50\n");
    printf("7.Ubat gigi RM 4.50\n");
    printf("8.Milo RM 8.90\n");
    printf("9.Peanut butter RM 7.50\n");
    printf("10.Roti RM 1.90\n");
    printf("Masukkan nombor item:\n\n\n");
    scanf("%d",&pilih);

    /*do{*/
    switch(pilih)
    {
    case 1:
    printf("Sabun RM 3.20");
    break;
    case 2:
    printf("Syampu RM14.90");
    break;
    case 3:
    printf("Maggi RM 2.70");
    break;
    case 4:
    printf("Kicap RM 2.10");
    break;
    case 5:
    printf("Sos RM 1.70");
    break;
    case 6:
    printf("Sardin RM 2.50");
    break;
    case 7:
    printf("Ubat gigi RM 4.50");
    break;
    case 8:
    printf("Milo RM 8.90");
    break;
    case 9:
    printf("Peanut butter RM 7.50");
    break;
    case 10:
    printf("Roti RM 1.90");
    break;
    default:
    printf("Tiada item yang dikehendaki lagi");
    }
    }
    /* } while(pilih<=10);*/

    /*jumlah=jumlah+harga;*/

    /*printf("Jumlah yang perlu dibayar
    ialah:%.2f",jumlah);*/

    i have get 1 problem in this progra m..
    want i compile ... i cant get are price ... so who cant tell me waht the program false

  2. #2
    Registered User CAP's Avatar
    Join Date
    May 2002
    Posts
    179
    What exactly are you asking??
    -Microsofts Visual C++ Introductory Kit-
    Current Projects: Learning Everything C.

    Everyone has a photographic memory, some people just don't have any film.
    ______________________________

    When was the last time you went for a colon cleansing? Because quite frankly, you're so backed up with crap that it's spilling out your mouth

  3. #3
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    I'm hardly a professional programmer as this code would suggest, but I like to give the real programmers a laugh or two.

    Like the first reply, I'm not sure what you wanted; however, I took a stab at it and assumed that you wanted to tally up the total of the items entered. If this is not correct please forgive me.

    #include<stdio.h>
    #include<conio.h>

    void main()
    {
    char pilih;
    int exit;
    float harga;
    float myPrice[4] = { 3.20, 14.90, 2.70, 2.10};
    char *myNames[4] = {"Sabun RM", "Syampu RM", "Maggi RM", "Sos RM"};

    const char myMenu[256] = "1) Sabun RM 3.20\n"
    "2) Syampu RM 14.90\n"
    "3) Maggi RM 2.70\n"
    "4) Sos RM 1.70"
    "\n\nMasukkan nombor item: ";

    exit = 0;
    harga = 0.0;

    while(exit < 11)
    {
    clrscr();
    printf("%s", myMenu);
    scanf("%c", &pilih);

    switch(pilih)
    {
    case '1': printf("\n%s %.2f", myNames[0], myPrice[0]);
    harga = harga + myPrice[0];
    flushall();
    break;

    case '2': printf("\n%s %.2f", myNames[1], myPrice[1]);
    harga = harga + myPrice[1];
    flushall();
    break;

    case '3': printf("\n%s %.2f", myNames[2], myPrice[2]);
    harga = harga + myPrice[2];
    flushall();
    break;

    case '4': printf("\n%s %.2f", myNames[3], myPrice[3]);
    harga = harga + myPrice[3];
    flushall();
    break;

    default: printf("\nThat selection is invalid");
    flushall();
    break;
    };

    getch();
    exit++;

    }

    printf("\n\nJumlah yang perlu dibayar ialah: %.2f",harga);
    }

    I dunno how the formatting will come on or how many bugs are in the code, but I gave it a shot.
    Last edited by ronin; 06-26-2002 at 12:03 AM.
    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >void main()
    This is wrong

    >formatting...
    code tags people... read my sig

    >const char myMenu[256] = " ...<snip>
    You don't need to specify the array size if you are populating it with a string at compile time.
    >const char myMenu[] = "some text";

    Feeling too lazy today to do anymore :P
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM