Ir para conteúdo
Fórum Script Brasil

spittfire

Membros
  • Total de itens

    3
  • Registro em

  • Última visita

Sobre spittfire

spittfire's Achievements

0

Reputação

  1. Consegui traduzir pra C mas por alguma razao ele nao esta salvando os valores nos strings: #include <stdio.h> #include <string.h> #define bool _Bool typedef int bool; int main() { bool p[4] = { true, true, false, false }; bool q[4] = { true, false, true, false }; char andor[3]; char snq[1]; char snp[1]; for (int i = 0; i <= 10; i++) { printf("\nVoce quer usar AND ou OR com as variaveis?\n"); scanf("%s", andor); printf("Voce quer NEGAR p? S/N\n"); scanf("%s", snp); printf("Voce quer NEGAR q? S/N\n"); scanf("%s", snq); printf("\n"); if (andor == "AND" || andor == "OR" && snq == "S" || snq == "N" && snp == "S" || snp == "N") { if (andor == "AND" && snp == "N" && snq == "N") { printf("p | q | p AND q\n"); for (int i = 0; i < 4; i++) { printf("%s | ", p); for (int j = 0; j < 1; j++) { printf("%s | ", q); printf("%s", p && q); } } } else if (andor == "AND" && snp == "S" && snq == "N") { printf("p | q | p AND q\n"); for (int i = 0; i < 4; i++) { printf("%s | ", p); for (int j = 0; j < 1; j++) { printf("%s | ", q); printf("%s", p && q); } } } else if (andor == "AND" && snp == "N" && snq == "S") { printf("p | q | p AND q\n"); for (int i = 0; i < 4; i++) { printf("%s | ", p); for (int j = 0; j < 1; j++) { printf("%s | ", q); printf("%s", p && q); } } } else if (andor == "AND" && snp == "S" && snq == "S") { printf("p | q | p AND q\n"); for (int i = 0; i < 4; i++) { printf("%s | ", p); for (int j = 0; j < 1; j++) { printf("%s | ", q); printf("%s", p && q); } } } else if (andor == "OR" && snp == "N" && snq == "N") { printf("p | q | p AND q\n"); for (int i = 0; i < 4; i++) { printf("%s | ", p); for (int j = 0; j < 1; j++) { printf("%s | ", q); printf("%s", p && q); } } } else if (andor == "OR" && snp == "S" && snq == "N") { printf("p | q | p AND q\n"); for (int i = 0; i < 4; i++) { printf("%s | ", p); for (int j = 0; j < 1; j++) { printf("%s | ", q); printf("%s", p && q); } } } else if (andor == "OR" && snp == "N" && snq == "S") { printf("p | q | p AND q\n"); for (int i = 0; i < 4; i++) { printf("%s | ", p); for (int j = 0; j < 1; j++) { printf("%s | ", q); printf("%s", p && q); } } } else if (andor == "OR" && snp == "S" && snq == "S") { printf("p | q | p AND q\n"); for (int i = 0; i < 4; i++) { printf("%s | ", p); for (int j = 0; j < 1; j++) { printf("%s | ", q); printf("%s", p && q); } } } else { printf("Erro: Favor digitar valores validos - Exemplo(AND, OR, S, N).\n"); } } } return 0; } Alguem sabe o que eu devo mudar?
  2. Acidentalmente criei dois tópicos iguais, desculpe. Se algum adm puder deletar eu ficaria grato
  3. Sou aluno de CC e tenho que realizar um trabalho de programação envolvendo tabelas verdade. O problema e que fiz todo o programa em C++ e acabei de ficar sabendo que a professora só aceitara o trabalho em C! Eu costumo fazer tudo em C++ e não tenho muito conhecimento de C sinceramente, então estava querendo uma ajuda se possivel! Segue o código: #include <iostream> #include <string> using namespace std; int main() { bool p[4] = { true, true, false, false }; bool q[4] = { true, false, true, false }; for (int i = 0; i <= 10; i++) { cout << "\nVoce quer usar AND ou OR com as variaveis?" << endl; string andor; cin >> andor; cout << "Voce quer NEGAR p? S/N" << endl; string snp; cin >> snp; cout << "Voce quer negar q? S/N" << endl; string snq; cin >> snq; cout << "\n"; if (andor == "AND" || andor == "OR" && snq == "S" || snq == "N" && snp == "S" || snp == "N") { if (andor == "AND" && snp == "N" && snq == "N") { cout << "p | q" << " | " << "p AND q" << endl; for (int i = 0; i < 4; i++) { cout << p << " | "; for (int j = 0; j < 1; j++) { cout << q << " | "; cout << (p && q); } cout << endl; } } else if (andor == "AND" && snp == "S" && snq == "N") { cout << "p | q" << " | " << "~p AND q" << endl; for (int i = 0; i < 4; i++) { cout << p << " | "; for (int j = 0; j < 1; j++) { cout << q << " | "; cout << (!(p) && q); } cout << endl; } } else if (andor == "AND" && snp == "N" && snq == "S") { cout << "p | q" << " | " << "p AND ~q" << endl; for (int i = 0; i < 4; i++) { cout << p << " | "; for (int j = 0; j < 1; j++) { cout << q << " | "; cout << (p && !(q)); } cout << endl; } } else if (andor == "AND" && snp == "S" && snq == "S") { cout << "p | q" << " | " << "~p AND ~q" << endl; for (int i = 0; i < 4; i++) { cout << p << " | "; for (int j = 0; j < 1; j++) { cout << q << " | "; cout << (!(p) && !(q)); } cout << endl; } } else if (andor == "OR" && snp == "N" && snq == "N") { cout << "p | q" << " | " << "p OR q" << endl; for (int i = 0; i < 4; i++) { cout << p << " | "; for (int j = 0; j < 1; j++) { cout << q << " | "; cout << (p || q); } cout << endl; } } else if (andor == "OR" && snp == "S" && snq == "N") { cout << "p | q" << " | " << "~p OR q" << endl; for (int i = 0; i < 4; i++) { cout << p << " | "; for (int j = 0; j < 1; j++) { cout << q << " | "; cout << (!(p) || q); } cout << endl; } } else if (andor == "OR" && snp == "N" && snq == "S") { cout << "p | q" << " | " << "p OR ~q" << endl; for (int i = 0; i < 4; i++) { cout << p << " | "; for (int j = 0; j < 1; j++) { cout << q << " | "; cout << (p || !(q)); } cout << endl; } } else if (andor == "OR" && snp == "S" && snq == "S") { cout << "p | q" << " | " << "~p OR ~q" << endl; for (int i = 0; i < 4; i++) { cout << p << " | "; for (int j = 0; j < 1; j++) { cout << q << " | "; cout << (!(p) || !(q)); } cout << endl; } } } else { cerr << "Erro: Favor digitar valores validos - Exemplo(AND, OR, S, N)." << endl; } } return 0; } Se alguém pudesse me dar uma luz. Tenho como mudar algumas partes do código e ele passaria como C? Ou terei que começar do 0 e me virar?
×
×
  • Criar Novo...