Page 1 of 3 123 LastLast
Results 1 to 10 of 21

Thread: รบกวนดูโค๊ดcทีคับ

  1. #1


    คือว่าไม่ต้องลงความเห็นแล้วนะคับ ขอบคุณทุกท่านที่มาลงความเห็นให้นะคับ

    #include<stdio.h>
    #include<conio.h>
    main()
    {
    clrscr();
    int temp,grade,tgrade,tcredit=0,credit,i,j,sub;
    printf("Enter num sub:");
    scanf("%d",&sub);
    for(i=1;i<=sub;i++)
    {
    printf("Enter credit %d :",i);
    scanf("%d",&credit);
    tcredit+=credit;
    }
    for(j=1;j<=sub;j++)
    {
    printf("Enter char grade %d :",j);
    scanf("%c%c",&grade);
    if ((grade == &#39;A&#39 || (grade == &#39;a&#39)
    { temp = 4; }
    if ((grade == &#39;B&#39 || (grade == &#39;b&#39)
    { temp = 3; }
    if ((grade == &#39;C&#39 || (grade == &#39;c&#39)
    { temp = 2; }
    if ((grade == &#39;D&#39 || (grade == &#39;d&#39)
    { temp = 1; }
    if ((grade == &#39;F&#39 || (grade == &#39;f&#39)
    { temp = 0; }

    tgrade+=temp;
    }
    printf("\nTotalcredit:%d",tcredit);
    printf("\nTotalgrade :%d",tgrade);
    getch();
    }[/b]


    gradeมันไม่ยอมรวมอะคับ สงสัยว่าจะผิดต้องไหนป่าวไม่แน่ใจ ไม่ได้จับนานสนิทเกาะ ผมสงสัยว่าtempจะไม่ได้เปลี่ยนค่า โปรแกรมนี้หาค่าเกรดเฉลี่ยคับ กรอกเกรดเป็นตัวอักขระคับรบกวนทีคับ
    [SIZE=2][color=#FFFFFF]www.CitecClub.Org[/color][/SIZE] [/b] [/url]

    </div>

  2. #2
    Junior Member
    Join Date
    Oct 2006
    Location
    Matrix
    Posts
    28


    บรรทัดที่18ทำไมมี %c สองตัวล่ะครับ หรือว่าผมมึน

    ลองใช้ case แทนดูรึยังครับ น่าจะเวิร์กกว่านะ เพราะผมก็เคยเขียนทำนองนี้ ใช้caseแทน
    [color=#006600]Mr.Anderson welcome back... we miss you...[/color]

  3. #3


    บรรทัดที่18ทำไมมี %c สองตัวล่ะครับ หรือว่าผมมึน
    [/b]

    ผมจำไม่ได้เหมือนกันคับ แต่มันต้องใส่เพราะไม่ใส่มันจะ
    printf("Enter credit %d :",i);
    ให้กรอกแค่อันเดียวอันที่เหลือมันเล่นข้ามหมดออกloopซะงั้นคับ
    ส่วนcase ใช้แล้วคับแต่ไม่ค่อยworkเท่าไรอย่างไรก็ขอบคุณคับที่แนะนำ
    [SIZE=2][color=#FFFFFF]www.CitecClub.Org[/color][/SIZE] [/b] [/url]

    </div>

  4. #4
    Senior Member
    Join Date
    Oct 2006
    Location
    thailand
    Posts
    182


    ที่คุณใช้ if ((grade == &#39;A&#39 || (grade == &#39;a&#39) มันไม่เข้าเงื่อนไขครับ
    ลอง Debug ดูก็ได้ครับ ว่ามันรับค่ามาเป็นอะไร

    ผมมีตัวอย่างในการ Compare มาให้ดูครับ แต่ใช้เป็น String แทน ครับ น่าจะประยุคใช้ได้

    Example:
    [code]/* strcmp example */
    #include <stdio.h>
    #include <string.h>

    int main ()
    {

  5. #5
    Senior Member
    Join Date
    Jul 2004
    Location
    Thailand
    Posts
    211


    ผมว่า ออกแบบใหม่ เหอะ algo มันแปลกๆ

    printf("\nTotalcredit:%d",tcredit);[/b]
    อันเนี้ย พอเข้าใจ ว่า เอา credit มา บวกกัน


    printf("\nTotalgrade :%d",tgrade);[/b]
    งง มันจะแสดงผล ในรูปแบบไหน ?? ทีละบรรทัดเหรอ??


    สนุกดี ภาษา c ทำให้นึกถึงสมัยเรียน....


  6. #6


    ผมว่า ออกแบบใหม่ เหอะ algo มันแปลกๆ

    [/b]
    ผมก็ว่าแบบนั้นแหละคับ ขอบคุณทั้ง2ท่านมากนะคับ เอิ้กๆลองคิดเล่นๆดูอ่ะคับ
    [SIZE=2][color=#FFFFFF]www.CitecClub.Org[/color][/SIZE] [/b] [/url]

    </div>

  7. #7
    Junior Member
    Join Date
    Jul 2007
    Posts
    0


    มาเยี่ยมด้วยคน

  8. #8
    Junior Member
    Join Date
    Aug 2007
    Posts
    3


    scanf("%c%c",&grade); <----------- ผมว่ามันผิด Syntax มากกว่านะครับ

    algo ถึงนะมึนๆ หน่อยแต่ก็ไม่น่าจาเปนปันหาอาไรกะโปรแรม คำนวนแบบนี้

    ผมว่า ตัวแปล grade นี่มานต้องเปน char ไม่ใช่หรอครับ

    เอ๊ะ หรือว่าเขียนผิดหว่า ชักงงแฮะ

  9. #9
    Junior Member
    Join Date
    Jul 2007
    Posts
    2


    loop อันที่สอง ใช้สวิสต์ไม่ดีกว่าเหรอค่ะ = ="


  10. #10



    ปล. ผมยังไม่ได้ลองไป compile เลย
    ตามความคิดผมนะ ลองดูที่อื่นถ้าไม่ ผิด ทามไมไม่ดูที่ if ละ เหงแต่ if แล้วไม่ลองใส่ else if ไปบ้างล่ะครับ เพราะว่าอาจจะมีส่วนก็ได้ เพิ่งเรียนไปเองอ่ะ เคยเจอปัญหาแบบ แก้ไม่ตก เหมือนกานยังไงก็ switch ดีกว่านะง่ายดี
    แล้วอีกอย่างนะ ลองอ่าน บรรทัดที่ error อ่ะคับดูว่าเขียนว่าไร ง่ายกว่านะ

Page 1 of 3 123 LastLast

Members who have read this thread : 0

Actions : (View-Readers)

There are no names to display.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •