Lỗi chương trình tính điểm trung bình

Chào mọi người! Em là thành viên mới (lập trình lẫn trang daynhauhoc.com ). Hiện tại em chỉ vừa mới bắt đầu với C và đang giải bài thì không hiểu nó sai chổ nào. Mong mọi người giúp đỡ ( tại vì em tự học chứ không có trường lớp).

Đề bài là: hỏi xem người dùng học khối nào? Nhập điểm vào và tính điểm trung bình.

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

char group;
float math, physics, chemistry, literature, history, geography, average;

int main(void) {
    printf("Whats your group ? (A/B)\n");
    scanf(" %c", &group);
    if (group == 'A'){
        printf("Enter your Math's mark : \n");
        scanf(" %f", &math);

        printf("Enter your Physics' mark : \n");
        scanf(" %f", &physics);

        printf("Enter your Chemistry's mark : \n");
        scanf(" %f", &chemistry);

        average = (math + physics + chemistry) / 3;

        printf("Your average is : %.1f ", average);
    } else {
        printf("Enter your Literature's mark :");
        scanf(" %f", &literature);

        printf("Enter your History' mark :");
        scanf(" %f", &history);

        printf("Enter your Geography's mark :");
        scanf(" %f", &geography);

        average = (literature + history + geography) / 3;

        printf("Your average is : %.1f ", average);
    }
    getch();
    return 0;
}

do em newbie nên ko đang hình được

Em phải cho mọi người biết em đang “giải cái gì?” chứ? :cry:

Dạ đề bài là hỏi xem người dùng học khối nào? Nhập điểm vào và tính điểm trung bình ạ!!!

Anh chạy thử thấy ổn mà?

ltd@office:~/workspace/tmp$ ./a.out
Whats your group ? (A/B)
A
Enter your Math’s mark :
5
Enter your Physics’ mark :
6
Enter your Chemistry’s mark :
7
Your average is : 6.0

ltd@office:~/workspace/tmp$ ./a.out
Whats your group ? (A/B)
B
Enter your Literature’s mark :5
Enter your History’ mark :6
Enter your Geography’s mark :7
Your average is : 6.0

nhưng máy em chạy nó ra có chọn group xong nó dừng lại luôn a ạ @@!

Thử lại với code này xem

#include <stdio.h>

char group;
float math, physics, chemistry, literature, history, geography, average;

int main(void) {
    printf("Whats your group ? (A/B)\n");
    scanf(" %c", &group);
    if (group == 'A'){
        printf("Enter your Math's mark : \n");
        scanf(" %f", &math);

        printf("Enter your Physics' mark : \n");
        scanf(" %f", &physics);

        printf("Enter your Chemistry's mark : \n");
        scanf(" %f", &chemistry);

        average = (math + physics + chemistry) / 3;

        printf("Your average is : %.1f ", average);
    } else {
        printf("Enter your Literature's mark :");
        scanf(" %f", &literature);

        printf("Enter your History' mark :");
        scanf(" %f", &history);

        printf("Enter your Geography's mark :");
        scanf(" %f", &geography);

        average = (literature + history + geography) / 3;

        printf("Your average is : %.1f ", average);
    }
    return 0;
}

Ổn rồi anh! Mà sao kì vậy anh? Chỉ bỏ bớt thư viện với getch(); thôi mà?

Anh bỏ mấy cái không cần thiết, đâu có sửa code gì đâu :frowning: anh không nghĩ do getch(). Có thể code trước của em compile lỗi?

@@! Em đang dùng Visual Studio 2013

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?