Untitled
unknown
plain_text
9 months ago
5.0 kB
8
Indexable
#include <stdio.h>
#include <stdlib.h>
int isAvailable(int opcoes[], int iterator) {
int availability = 1;
int i = 0;
for(i = 0; i < iterator; i++) {
if (opcoes[iterator] == opcoes[i]) {
availability = 0;
}
}
return availability;
}
void printMenu() {
printf("\n*****COMPARANDO OS ATRIBUTOS*****\n\n");
printf("1. Comparar População.\n");
printf("2. Comparar Área.\n");
printf("3. Comparar PIB.\n");
printf("4. Comparar Número de Pontos Turísticos.\n");
printf("5. Comparar Densidade Populacional.\n");
printf("6. Comparar PIB per Capta.\n");
printf("7. Comparar Super Poder.\n");
printf("8. Sair\n\n");
printf("Escolha sua opção: ");
}
int checkPop(int opcoes[], int iterator) {
int hasPop = 0;
int i = 0;
for(i = 0; i < iterator; i++) {
if (opcoes[i] == 1) {
hasPop = 1;
}
}
return hasPop;
}
int checkArea(int opcoes[], int iterator) {
int hasArea = 0;
int i = 0;
for(i = 0; i < iterator; i++) {
if (opcoes[i] == 2) {
hasArea = 1;
}
}
return hasArea;
}
int checkPIB(int opcoes[], int iterator) {
int hasPIB = 0;
int i = 0;
for(i = 0; i < iterator; i++) {
if (opcoes[i] == 3) {
hasPIB = 1;
}
}
return hasPIB;
}
int checkNumTur(int opcoes[], int iterator) {
int hasNumTur = 0;
int i = 0;
for(i = 0; i < iterator; i++) {
if (opcoes[i] == 4) {
hasNumTur = 1;
}
}
return hasNumTur;
}
int checkDensi(int opcoes[], int iterator) {
int hasDensi = 0;
int i = 0;
for(i = 0; i < iterator; i++) {
if (opcoes[i] == 5) {
hasDensi = 1;
}
}
return hasDensi;
}
int checkPPP(int opcoes[], int iterator) {
int hasPPP = 0;
int i = 0;
for(i = 0; i < iterator; i++) {
if (opcoes[i] == 6) {
hasPPP = 1;
}
}
return hasPPP;
}
int checkSuper(int opcoes[], int iterator) {
int hasSuper = 0;
int i = 0;
for(i = 0; i < iterator; i++) {
if (opcoes[i] == 7) {
hasSuper = 1;
}
}
return hasSuper;
}
void printDynamicMenu(int opcoes[], int iterator) {
if (iterator == 0) {
printMenu();
return;
}
int hasPop = checkPop(opcoes, iterator);
int hasArea = checkArea(opcoes, iterator);
int hasPIB = checkPIB(opcoes, iterator);
int hasNumTur = checkNumTur(opcoes, iterator);
int hasDensi = checkDensi(opcoes, iterator);
int hasPPP = checkPPP(opcoes, iterator);
int hasSuper = checkSuper(opcoes, iterator);
printf("\n*****COMPARANDO OS ATRIBUTOS*****\n\n");
if (!hasPop) {
printf("1. Comparar População.\n");
}
if (!hasArea) {
printf("2. Comparar Área.\n");
}
if (!hasPIB) {
printf("3. Comparar PIB.\n");
}
if (!hasNumTur) {
printf("4. Comparar Número de Pontos Turísticos.\n");
}
if (!hasDensi) {
printf("5. Comparar Densidade Populacional.\n");
}
if (!hasPPP) {
printf("6. Comparar PIB per Capta.\n");
}
if (!hasSuper) {
printf("7. Comparar Super Poder.\n");
}
printf("8. Sair\n\n");
printf("Escolha sua opção: ");
}
int main() {
int opcoes[8] = {0, 0, 0, 0, 0, 0, 0, 0};
int iterator = 0;
do {
printDynamicMenu(opcoes, iterator);
scanf("%d", &opcoes[iterator]);
while(!isAvailable(opcoes, iterator)) {
printf("\n***OPÇÃO JÁ ESCOLHIDA, ESCOLHA OUTRA***\n\n");
printDynamicMenu(opcoes, iterator);
scanf("%d", &opcoes[iterator]);
}
switch(opcoes[iterator]) {
case 1:
printf("\n###Comparando Populaçao###\n");
break;
case 2:
printf("\n###Comparando Área###\n");
break;
case 3:
printf("\n###Comparando PIB###\n");
break;
case 4:
printf("\n###Comparando Num Pontos Turísticos###\n");
break;
case 5:
printf("\n###Comparando Densidade Populacional###\n");
break;
case 6:
printf("\n###Comparando PIB per Capta###\n");
break;
case 7:
printf("\n###Comparando Super Poder###\n");
break;
case 8:
printf("\n###Saindo...###\n\n");
break;
default:
printf("\n###Opção Inválida###\n");
iterator--;
}
iterator++;
} while (opcoes[iterator - 1] != 8);
return 0;
}Editor is loading...
Leave a Comment