hello everybody..
here is my Assignment Code..

#include <stdio.h>
#include <windows.h>

int Attendance[50][50] = {0};
int studPresence[] = {0}, weekPresence[] = {0};
int i, x;
int week, student;
char SubCode[30];

void InputFunction();
void WeekAttendance();
void StudentAttendance();

void main()
{
	int answer;

	while(answer != 4 || answer > 4 || answer < 1)
	{
		printf("(1) User Input\n");
		printf("(2) Week Attendance\n");
		printf("(3) Student Attendance\n");
		printf("(4) Quit\n");
		printf("Please Type And Enter\n");
		scanf("%d", &answer);

		if(answer == 1)
			InputFunction();

		else if(answer == 2)
			WeekAttendance();

		else if(answer == 3)
			StudentAttendance();

		else if(answer == 4)
			exit(1);

		else
		{
			printf("You Have Enter Out of Range\n");
			printf("Please Re-enter Again\n");
		}
	}
}

void InputFunction()
{
	system("cls");
	printf("What is your Course Code? ");
	scanf("%s", SubCode);
	printf("How many weeks? ");
	scanf("%d", &week);
	printf("How many students in this class? ");
	scanf("%d", &student);

	for(i=0; i<student; i++)
	{
		system("cls");
		printf("STUDENT %d\n", i+1);
		printf("==========\n");
		for(x=0; x<week; x++)
		{
			printf("Present in Week %d? <1 = Yes; 0 = No> ",x+1);
			scanf("%d", &Attendance[x][i]);
		}
	}

	for(i=0; i<student; i++)
		for(x=0; x<week; x++)
			studPresence[i] += Attendance[x][i];

	for(x=0; x<week; x++)
		for(i=0; i<student; i++)
			weekPresence[x] += Attendance[x][i];
}

void WeekAttendance()
{
	system("cls");
	printf("Attendance for each Week\n");
	printf("========================\n");

	for(x=0; x<week; x++)
		printf("Week No %d : %d students present\n", x+1, weekPresence[x]);
	printf("---------- END OF REPORT ----------\n\n");
	exit(1);
}

void StudentAttendance()
{
	system("cls");
	printf("Student Attendance - %s\n", SubCode);
	printf("=======================\n");

	for(i=0; i<student; i++)
		printf("Student %d : %d days present\n", i+1, studPresence[i]);
	printf("---------- END OF REPORT ----------\n\n");
	exit(1);
}

when i compile the code and execute the program ..
i try to enter the input for example
i enter 2 week 2 students;
student 1 = present in 2 weeks;
student 2 = no present in 2 weeks;
but the report of week and report of student are show me incorrect answer..
what's the problem ?

Edited 6 Years Ago by gahhon: n/a

hey I solved your problem try this code

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

using namespace std;

int Attendance[50][50] = {0};
static int studPresence[] = {0};
static int weekPresence[] = {0};
int i, x;
int week, student;
char SubCode[30];

void InputFunction();
void WeekAttendance();
void StudentAttendance();

void main()
{
    int answer = 0;

    while(answer != 4 || answer > 4 || answer < 1)
    {
        printf("(1) User Input\n");
        printf("(2) Week Attendance\n");
        printf("(3) Student Attendance\n");
        printf("(4) Quit\n");
        printf("Please Type And Enter\n");
        scanf("%d", &answer);

        if(answer == 1)
            InputFunction();

        else if(answer == 2)
            WeekAttendance();

        else if(answer == 3)
            StudentAttendance();

        else if(answer == 4)
            return;

        else
        {
            printf("You Have Enter Out of Range\n");
            printf("Please Re-enter Again\n");
        }
    }
}

void InputFunction()
{
    system("cls");
    printf("What is your Course Code? ");
    scanf("%s", SubCode);
    printf("How many weeks? ");
    scanf("%d", &week);
    printf("How many students in this class? ");
    scanf("%d", &student);
    
    for (i = 0; i < week; i++)
        weekPresence[i] = 0;

    for (i = 0; i < student; i++)
        studPresence[i] = 0;

    for(i=0; i < student; i++)
    {
        system("cls");
        printf("STUDENT %d\n", i+1);
        printf("==========\n");
        for(x=0; x < week; x++)
        {
            printf("Present in Week %d? <1 = Yes; 0 = No> ",x+1);
            scanf("%d", &Attendance[x][i]);
        }
    }
    printf("\n\n");
}

void WeekAttendance()
{
    for (i = 0; i < week; i++)
        weekPresence[i] = 0;

    for (x = 0; x < week; x++)
        for (i = 0; i < student; i++)
            weekPresence[x] += Attendance[x][i];

    system("cls");
    printf("Attendance for each Week\n");
    printf("========================\n");

    for(x=0; x<week; x++)
        printf("Week No %d : %d students present\n", x+1, weekPresence[x]);
    printf("---------- END OF REPORT ----------\n\n");
    return;
}

void StudentAttendance()
{
    for (i = 0; i < student; i++)
        studPresence[i] = 0;

    for(i=0; i < student; i++)
        for(x=0; x < week; x++)
            studPresence[i] += Attendance[x][i];

    system("cls");
    printf("Student Attendance - %s\n", SubCode);
    printf("=======================\n");

    for(i=0; i < student; i++)
    {
        printf("Student %d : %d weeks present\n", i+1, studPresence[i]);
    }
    printf("---------- END OF REPORT ----------\n\n");
    return;
}

yeah..
i solved it already..
it the int array type problem.
by the way..
thanks for helping.. =D

This question has already been answered. Start a new discussion instead.