I'm making a code for class. We're supposed to make a game-ish thing where the user sees a set of birthdays, and if their birthday is in the set, says Yes or No, then sees a new set, then answers Yes or No. The computer is supposed to guess their birthday
#include <iostream>
#include <string>
int main()
{
int a = 0, b = 0, c = 0, d = 0, e = 0;
int Yes = 1, No = 0;
std::cout << "State Y or N if your birthday is in the set\n";
std::cout << "Set 1: 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31\n";
std::cin >> a;
int f = a*2^0;
std::cout << "State Y or N if your birthday is in the set\n";
std::cout << "Set 2: 2 3 6 7 10 11 14 15 18 19 22 23 26 27 30 31\n";
std::cin >> b;
int g = b*2^1;
std::cout << "State Y or N if your birthday is in the set\n";
std::cout << "Set 3: 4 5 6 7 12 13 14 15 20 21 22 23 28 29 30 31\n";
std::cin >> c ;
int h = c*2^2;
std::cout << "State Y or N if your birthday is in the set\n";
std::cout << "Set 4: 8 9 10 11 12 13 14 15 24 25 26 27 28 29 30 31\n";
std::cin >> d;
int i = d*2^3;
std::cout << "State Y or N if your birthday is in the set\n";
std::cout << "Set 5: 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31\n";
std::cin >> e;
int j = e*2^4;
int K = f+g+h+i+j;
std::cout << " Your number is " << K << "!\n";
}
the problem is that it wont let me get it so that the user can input multiple answers. Like the have to see a set, input yes or no, then get a new set and say yes or no.
I was thinking that if the user was to input Yes, it would become registered as a 1 and if no, it would register as a zero, then input it into the equation in place of a, then continuing with b, c, d, and e.
#include <iostream>
int main()
{
std::cout << "Enter the number to convert: ";
int n { };
std::cin >> n;
std::cout << '\n';
int a[10];
int i = 0;
for (i = 0; n > 0; i++)
{
a[i] = n % 2;
n = n / 2;
}
std::cout << "Binary of the given number = ";
for (i = i - 1; i >= 0; i--)
{
std::cout << a[i];
}
std::cout << '\n';
}
the code is supposed to get either a 1 or 0 from each set based on the user's input, then receive a binary number. That binary number is then supposed to be converted to a decimal that is the user's birthday.
Change each of your input requests, to: std::cout << "State 1 for 'Yes' or 0 for 'No', if your birthday is in the set\n";
But, even after changing it to look for 1's and 0's, the program still does not deliver a correct answer. I think you may need to use POW function, as I don't think '^' is doing what you are intending.
{EDIT}
I used the pow function, and things worked out very well. Here it is..
#include <iostream>
int main()
{
int a = 0, b = 0, c = 0, d = 0, e = 0, K = 0;
int Yes = 1, No = 0;
std::cout << "State 1 for 'Yes' or 0 for 'No', if your birthday is in the set\n";
std::cout << "Set 1: 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31\n";
std::cin >> a;
int f = pow(a*2,0);
std::cout << "State 1 for 'Yes' or 0 for 'No', if your birthday is in the set\n";
std::cout << "Set 2: 2 3 6 7 10 11 14 15 18 19 22 23 26 27 30 31\n";
std::cin >> b;
int g = pow(b*2,1);
std::cout << "State 1 for 'Yes' or 0 for 'No', if your birthday is in the set\n";
std::cout << "Set 3: 4 5 6 7 12 13 14 15 20 21 22 23 28 29 30 31\n";
std::cin >> c ;
int h = pow(c*2,2);;
std::cout << "State 1 for 'Yes' or 0 for 'No', if your birthday is in the set\n";
std::cout << "Set 4: 8 9 10 11 12 13 14 15 24 25 26 27 28 29 30 31\n";
std::cin >> d;
int i= pow(d*2,3);
std::cout << "State 1 for 'Yes' or 0 for 'No', if your birthday is in the set\n";
std::cout << "Set 5: 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31\n";
std::cin >> e;
int j = pow(e*2,4);;
K = (f+g+h+i+j);
std::cout << " Your number is " << K << "!\n";
}