コード例 #1
0
ファイル: play.c プロジェクト: sdzharkov/ECS30
//ask the user for a play
void get_play(Board board) {
	int enter_row, enter_col;
	while(1){ //while still true, keep going through this loop
		printf("Enter row a row between 0-%d and a column between 0-%d: ", board.row - 1, board.col - 1);
		scanf("%d %d", &enter_row, &enter_col);
		enter_row = board.row - enter_row - 1;
		if (in_bounds(board, enter_row, enter_col)) {
			if (board.tile[enter_row][enter_col].revealed == '!') {
				if (option_2(board, enter_row, enter_col)) {
					break;
				}
				else {
					continue;
				}
			}
			else if (board.tile[enter_row][enter_col].revealed == '?') {
				if (option_3(board, enter_row, enter_col)) {
					break;
				}
				else {
					continue;
				}
			}
			else if (board.tile[enter_row][enter_col].revealed == '#') {
				if (option_1(board, enter_row, enter_col)) {
					reveal_board(board, enter_row, enter_col, 0); 
					break;
				}
				else {
					continue;
				}
			}
			else {
				printf("This tile is already revealed.\n");
				continue;
			}
		}
		else {
			continue;
		}
	}
	if (check_win(board)) {
			print_board(board);
			printf("You Won!!\n");
			exit (0); //end the program because the game is over and the user has lost 
	}

	if (isgameover(board)) {
			print_board(board);
			printf("You Lost :(\n");
			exit(0); //end the program because the game is over and the user has lost
	}
	return;
}
コード例 #2
0
void main() {
    printf("********************************************************************\n");
    printf("                 Climate Temperature Viewer 2014 (1)                \n");
    printf("********************************************************************\n\n");

    //Printing Menu
    int menu_choice;
    printf("Select Option:\n");
    printf(" 1. The mean temperatures for any selected day and month.\n");
    printf(" 2. The highest maximum temperature reached for the selected month.\n");
    printf(" 3. Display the days with three highest maximum temperatures on each month.\n");
    printf(" 4. Display day of the month with the lowest temperature\n");
    printf(" 5. Display the number of \"hot\" days which has more than mean temperature of 28 Degree Celsius for the selected month in whole number\n\n");


    do {
        printf("Your Option: ");
        scanf("%d", &menu_choice);
        switch (menu_choice) {
        case 1:
            option_1();
            break;
        case 2:
            option_2();
            break;
        case 3:
            option_3();
            break;
        case 4:
            option_4();
            break;
        case 5:
            option_5();
            break;
        default:
            printf("Invalid Input\n");
        }
    } while (menu_choice<1 || menu_choice>5);
}
コード例 #3
0
/**
 * Alphabetize the list of employees (choice = 6).
 * Who gets the highest salary? (choice = 7).
 */
employee* option_67(employee **head, int choice)
{
	int i;
	
	struct employee* new_employee;
	struct employee* cursor = *head;	
	int number_of_employees = get_size(*head);
	employee *employees_array = NULL;
	struct employee* head_tmp = NULL;
	
	if(*head == NULL)
	{
		return NULL;
	}
	
	if(employees_array == NULL)
	{
		employees_array = (employee *)malloc(sizeof(employee) * number_of_employees);
		i = 0;
 
        while (cursor != NULL)
        {
            employees_array[i] = *cursor;
            cursor = cursor->next;
            i++;
        }
		
		if (choice == 7)
		{
			qsort(employees_array, number_of_employees, sizeof(struct employee), compare_by_salary);
		}
		else
		{
			qsort(employees_array, number_of_employees, sizeof(struct employee), compare_by_last_name);
		}
		
        for (i = number_of_employees - 1; i >= 0; i--)
		{
			new_employee = (employee *)malloc(sizeof(employee));
			strcpy(new_employee->first_name, employees_array[i].first_name);
	        strcpy(new_employee->last_name, employees_array[i].last_name);
	        strcpy(new_employee->ssn, employees_array[i].ssn);
	        new_employee->gender = employees_array[i].gender;
            new_employee->hours = employees_array[i].hours;
            new_employee->rate = employees_array[i].rate;
	        new_employee->salary = employees_array[i].salary;
            new_employee->next = NULL;
			
			if(head_tmp == NULL)
	        {
	            head_tmp = new_employee;
	        }
			else
			{
			    new_employee->next = head_tmp;
			    head_tmp = new_employee;
			}
		}		
	}
	
    return option_1(head_tmp, employees_array, choice);
}
コード例 #4
0
/**
 * Main.
 */
int main ()
{
    char* data = "data.txt";
	int input;
	int i;
	
	employee* head;
	employee* employees_array = NULL;
    
	
	head = load(data);
	
	if (head == NULL)
    {
        printf("Could not load %s.\n", data);
        return 1;
    }	
	
	do
	{
	    input = display_menu();
        
        switch (input)
        {
        case 1:
			employees_array = option_1(head, employees_array, 1);
            break;
        case 2:
			employees_array = option_2(&head, employees_array);
            break;
        case 3:
            employees_array = option_3(&head, employees_array);
            break;
        case 4:
            employees_array = option_45(&head, 4);
            break;
		case 5:
		    employees_array = option_45(&head, 5);
            break;
        case 6:
            employees_array = option_67(&head, 6);
            break;
        case 7:
		    employees_array = option_67(&head, 7);
            break;
        case 8:	
		    option_8(employees_array);
            break;
        }
    }
    while(input != 8);
	
	free_employees_array(employees_array);
	unload(&head);


    if (head != NULL)
    {
        printf("Could not unload %s.\n", data);
        return 2;
    }

	printf("\nGoodbye!\n\n");
    system("pause");
    return 0;
}