1
I tried to make this game based on the Magic Cards. As I am still learning, that’s how I managed to do it. I would like to see other versions to know how I could have done and what I did of "wrong".
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <locale.h>
main()
{
setlocale(LC_ALL, "Portuguese");
//Variavel
int v1, v2, v3, v4, v5, v6;
int resultado;
char alternativa;
//Group 1
printf("Pense em um número entre 1 e 63.\n");
system("pause");
printf("O número está neste grupo?\n");
printf("1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,\n");
printf("35,37,39,41,43,45,47,49,51,53,55,57,59,61,63\n");
printf("s!\n");
printf("n!\n");
scanf("%s", &alternativa);
if (alternativa == 's') {
v1 = 1;
}
else if (alternativa == 'n') {
v1 = 0;
}
//Group 2
printf("O número está neste grupo?\n");
printf("2,3,6,7,10,11,14,15,18,19,22,23,26,27,30,31,34,\n");
printf("35,38,39,42,43,46,47,50,51,54,55,58,59,62,63\n");
printf("s!\n");
printf("n!\n");
scanf("%s", &alternativa);
if (alternativa == 's') {
v2 = 2;
}
else if (alternativa == 'n') {
v2 = 0;
}
//Group 3
printf("O número está neste grupo?\n");
printf("4,5,6,7,12,13,14,15,20,21,22,23,28,29,30,31,\n");
printf("37,38,39,44,45,46,47,52,53,54,55,60,61,62,63\n");
printf("s!\n");
printf("n!\n");
scanf("%s", &alternativa);
if (alternativa == 's') {
v3 = 4;
}
else if (alternativa == 'n') {
v3 = 0;
}
//Group 4
printf("O número está neste grupo?\n");
printf("8,9,10,11,12,13,14,15,24,25,26,27,28,29,30,31,\n");
printf("40,41,42,43,44,45,46,47,56,57,58,59,60,61,62,63\n");
printf("s!\n");
printf("n!\n");
scanf("%s", &alternativa);
if (alternativa == 's') {
v4 = 8;
}
else if (alternativa == 'n') {
v4 = 0;
}
//Group 5
printf("O número está neste grupo?\n");
printf("16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,\n");
printf("48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63\n");
printf("s!\n");
printf("n!\n");
scanf("%s", &alternativa);
if (alternativa == 's') {
v5 = 16;
}
else if (alternativa == 'n') {
v5 = 0;
}
//Group 6
printf("O número está neste grupo?\n");
printf("32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,\n");
printf("48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63\n");
printf("s!\n");
printf("n!\n");
scanf("%s", &alternativa);
if (alternativa == 's') {
v6 = 32;
}
else if (alternativa == 'n') {
v6 = 0;
}
//
resultado = v1 + v2 + v3 + v4 + v5 + v6;
printf("O número é:%d\n", resultado);
system("pause");
return 0;
}
vc can start using "Cout" instead of "printf", see this thread: https://stackoverflow.com/questions/2872543/printf-vs-cout-in-c
– Sérgio S. Filho
You can also use
cin
which is the standard input flow of C++: http://www.cplusplus.com/reference/iostream/cin/. I also suggest reading a few Good Practices in C++, This can help you improve your code.– KelvinS
Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the site).
– Maniero