ช่วยชี้แนะผมทีครับพอดีผมเรียนด้านนี้แต่ผมยังเรียนแบบเบสิกมากเลยไม่ค่อยชำนาญครับ code บางตัวอาจจะมีถูกผิดครับ
#include <stdio.h>
main() {
int score1,score2,score3,total=0;
printf("Enter your score1: ");
scanf("%d",&score1);
printf("Enter your score2: ");
scanf("%d",&score2);
printf("Enter your score3: ");
scanf("%d",&score3);
total=score1+score2+score3;
printf("Total = %d",total);
if(total >=80);
printf("You are Grade A");
else if(total >=75)
printf("You are Grade B+");
else if(total >=70)
printf("You are Grade B");
else if(total >=65)
printf("You are Grade C+");
else if (total >=60)
printf("You are Grade C");
else if (total >= 55)
printf("You are Grade D+");
else if (total >=50)
printf("You are Grade D");
else(total >=0)
printf("You are Grade F");
return 0;
}
คือผมลองทำโจทย์จากเว็บไซต์นึงอะครับ(พอดีช่วงนี้ไม่มีอะไรทำ)
โจทย์ :
A ถ้าคะแนนรวมของนักเรียนอยู่ในช่วง 80 - 100
B+ ถ้าคะแนนรวมของนักเรียนอยู่ในช่วง 75 - 79
B ถ้าคะแนนรวมของนักเรียนอยู่ในช่วง 70 - 74
C+ ถ้าคะแนนรวมของนักเรียนอยู่ในช่วง 65 - 69
C ถ้าคะแนนรวมของนักเรียนอยู่ในช่วง 60 - 64
D+ ถ้าคะแนนรวมของนักเรียนอยู่ในช่วง 55 - 59
D ถ้าคะแนนรวมของนักเรียนอยู่ในช่วง 50 - 54
F ถ้าคะแนนรวมของนักเรียนอยู่ในช่วง 0 - 49
ปล.อยากให้อธิบายมากกว่าส่ง code ตรงๆมาให้ครับ
ปล.2 ผมเห็นโค้ดนึงจาก Youtube แล้วผมลองเขียนเองกลับ error แต่ลอง copy & paste มันดัน compile & Run ได้เฉยเลยครับข้อนี้งงมาก แต่ก็ยืนยันว่าผมเขียนเหมือนหมดทุกอย่างไม่มีลืม ; ด้วยครับ
ทำไมถึง error แบบนี้ 'else' without a previous 'if'
#include <stdio.h>
main() {
int score1,score2,score3,total=0;
printf("Enter your score1: ");
scanf("%d",&score1);
printf("Enter your score2: ");
scanf("%d",&score2);
printf("Enter your score3: ");
scanf("%d",&score3);
total=score1+score2+score3;
printf("Total = %d",total);
if(total >=80);
printf("You are Grade A");
else if(total >=75)
printf("You are Grade B+");
else if(total >=70)
printf("You are Grade B");
else if(total >=65)
printf("You are Grade C+");
else if (total >=60)
printf("You are Grade C");
else if (total >= 55)
printf("You are Grade D+");
else if (total >=50)
printf("You are Grade D");
else(total >=0)
printf("You are Grade F");
return 0;
}
คือผมลองทำโจทย์จากเว็บไซต์นึงอะครับ(พอดีช่วงนี้ไม่มีอะไรทำ)
โจทย์ :
A ถ้าคะแนนรวมของนักเรียนอยู่ในช่วง 80 - 100
B+ ถ้าคะแนนรวมของนักเรียนอยู่ในช่วง 75 - 79
B ถ้าคะแนนรวมของนักเรียนอยู่ในช่วง 70 - 74
C+ ถ้าคะแนนรวมของนักเรียนอยู่ในช่วง 65 - 69
C ถ้าคะแนนรวมของนักเรียนอยู่ในช่วง 60 - 64
D+ ถ้าคะแนนรวมของนักเรียนอยู่ในช่วง 55 - 59
D ถ้าคะแนนรวมของนักเรียนอยู่ในช่วง 50 - 54
F ถ้าคะแนนรวมของนักเรียนอยู่ในช่วง 0 - 49
ปล.อยากให้อธิบายมากกว่าส่ง code ตรงๆมาให้ครับ
ปล.2 ผมเห็นโค้ดนึงจาก Youtube แล้วผมลองเขียนเองกลับ error แต่ลอง copy & paste มันดัน compile & Run ได้เฉยเลยครับข้อนี้งงมาก แต่ก็ยืนยันว่าผมเขียนเหมือนหมดทุกอย่างไม่มีลืม ; ด้วยครับ