Create a game where players convert hexadecimal numbers to d
Create a game where players convert hexadecimal numbers to decimal ones. a. Display a random hexadecimal value from 00 to ff. b. Player enters decimal equivalent, input is checked for Right or Wrong. c. 16 points for Right answer, -16 points for wrong answer. d. 16 rounds, then Game is over. e. Display round counter and running score; display right answer when player is Wrong.
this is my code but it is not working can someone help me please
int main ()
 {
 int points=0;
 int answer[16];
cout<< \"CONVERT THE FOLLOWING HEXADECIMALS INTO DECIMAL:\"<< endl;
 cout<< \"Round 1. d3\" << endl;
 cin>> answer[0];
    if (answer[0]==211)
    {points = points+ 16;
    cout<< \"Great job you have \"<<points<<\" Points!\"<<endl;}
   else { points = 0;
    cout<< \"Sorry wrong answer! Correct answer is 211, but nice try!\"<<endl;
    cout <<\"You have: \"<<points<<\" points\"<<endl;
    }
 
 
 cout<< \"Round 2. 6e\" << endl;
 cin>> answer[1];
    if (answer[1]==110)
    {points = points+ 16;
    cout<< \"Great job you have \"<<points<<\" Points!\"<<endl;}
    else { points = points - 16;
     cout<< \"Sorry wrong answer! Correct answer is 110, but nice try!\"<<endl;
     cout <<\"You have: \"<<points<<\" points\"<<endl;
    }
   cout<< \"Round 3. 78\" << endl;
 cin>> answer[2];
    if (answer[2]==120)
    {points = points + 16;
    cout<< \"Great job you have \"<<points<<\" Points!\"<<endl;}
     else { points = points - 16;
     cout<< \"Sorry wrong answer! Correct answer is 120, but nice try!\"<<endl;
     cout <<\"You have: \"<<points<<\" points\"<<endl;
    }
   cout<< \"Round 4. f6\" << endl;
 cin>> answer[3];
    if (answer[3]==246)
    {points = points+ 16;
    cout<< \"Great job you have \"<<points<<\" Points!\"<<endl;}
     else { points = points - 16;
     cout<< \"Sorry wrong answer, nice try!\"<<endl;
     cout <<\"You have: \"<<points<<\" points\"<<endl;
    }
 
    cout<< \"Round 5. 23\" << endl;
 cin>> answer[4];
    if (answer[4]==35)
    {points = points + 16;
    cout<< \"Great job you have \"<<points<<\" Points!\"<<endl;}
     else { points = points - 16;
     cout<< \"Sorry wrong answer! Correct answer is 35, but nice try!\"<<endl;
     cout <<\"You have: \"<<points<<\" points\"<<endl;
    }
 
 cout<< \"Round 6. 5d\" << endl;
 cin>> answer[5];
    if (answer[5]==93)
    {points = points+ 16;
    cout<< \"Great job you have \"<<points<<\" Points!\"<<endl;}
     else { points = points - 16;
     cout<< \"Sorry wrong answer! Correct answer is 93 nice try!\"<<endl;
     cout <<\"You have: \"<<points<<\" points\"<<endl;
    }
 
 cout<< \"Round 7. e6\" << endl;
 cin>> answer[6];
    if (answer[6]==230)
    {points = points + 16;
    cout<< \"Great job you have \"<<points<<\" Points!\"<<endl;}
     else { points = points - 16;
     cout<< \"Sorry wrong answer! Correct answer is 230, but nice try!\"<<endl;
     cout <<\"You have: \"<<points<<\" points\"<<endl;
    }
    cout<< \"Round 8. f3\" << endl;
 cin>> answer[7];
    if (answer[7]==243)
    {points = points+ 16;
    cout<< \"Great job you have \"<<points<<\" Points!\"<<endl;}
     else { points = points - 16;
     cout<< \"Sorry wrong answer! Correct answer is 243, but nice try!\"<<endl;
     cout <<\"You have: \"<<points<<\" points\"<<endl;
    }
 
    cout<< \"Round 9. 7f\" << endl;
 cin>> answer[8];
    if (answer[8]==127)
    {points = points+ 16;
    cout<< \"Great job you have \"<<points<<\" Points!\"<<endl;}
     else { points = points - 16;
     cout<< \"Sorry wrong answer! Correct answer is 127, but nice try!\"<<endl;
     cout <<\"You have: \"<<points<<\" points\"<<endl;
    }
   cout<< \"Round 10. 1d\" << endl;
 cin>> answer[9];
    if (answer[9]==29)
    {points = points + 16;
    cout<< \"Great job you have \"<<points<<\" Points!\"<<endl;}
     else { points = points - 16;
     cout<< \"Sorry wrong answer! Correct answer is 29, but nice try!\"<<endl;
     cout <<\"You have: \"<<points<<\" points\"<<endl;
    }
   cout<< \"Round 11. 7f\" << endl;
 cin>> answer[10];
    if (answer[10]==127)
    {points = points+ 16;
    cout<< \"Great job you have \"<<points<<\" Points!\"<<endl;}
     else { points = points - 16;
     cout<< \"Sorry wrong answer! Correct answer is 127, but nice try!\"<<endl;
     cout <<\"You have: \"<<points<<\" points\"<<endl;
    }
   cout<< \"Round 12. e3\" << endl;
 cin>> answer[11];
    if (answer[11]==227)
    {points = points+ 16;
    cout<< \"Great job you have \"<<points<<\" Points!\"<<endl;}
     else { points = points - 16;
     cout<< \"Sorry wrong answer! Correct answer is 227, but nice try!\"<<endl;
     cout <<\"You have: \"<<points<<\" points\"<<endl;
    }
   cout<< \"Round 13. 4f\" << endl;
 cin>> answer[12];
    if (answer[12]==79)
    {points = points+ 16;
    cout<< \"Great job you have \"<<points<<\" Points!\"<<endl;}
     else { points = points - 16;
     cout<< \"Sorry wrong answer! Correct answer is 79, but nice try!\"<<endl;
     cout <<\"You have: \"<<points<<\" points\"<<endl;
    }
 
    cout<< \"Round 14. 9d\" << endl;
 cin>> answer[13];
    if (answer[13]==157)
    {points =points + 16;
    cout<< \"Great job you have \"<<points<<\" Points!\"<<endl;}
     else { points = points - 16;
     cout<< \"Sorry wrong answer! Correct answer is 157, but nice try!\"<<endl;
     cout <<\"You have: \"<<points<<\" points\"<<endl;
    }
   cout<< \"Round 15. 7a\" << endl;
 cin>> answer[14];
    if (answer[14]==122)
    {points = points + 16;
    cout<< \"Great job you have \"<<points<<\" Points!\"<<endl;}
     else { points = points - 16;
     cout<< \"Sorry wrong answer! Correct answer is 122, but nice try!\"<<endl;
     cout <<\"You have: \"<<points<<\" points\"<<endl;
    }
 
 cout<< \"Round 16. 3a\" << endl;
 cin>> answer[15];
    if (answer[15]==58)
    {points = points + 16;
    cout<< \"Great job you have \"<<points<<\" Points!\"<<endl;}
     else { points = points - 16;
     cout<< \"Sorry wrong answer! Correct answer is 58, but nice try!\"<<endl;
     cout <<\"You have: \"<<points<<\" points\"<<endl;
    }
   cout<<\"Thank you for playing, your final SCORE: \"<<points<<\" POINTS\"<<endl;
 
 
 
 
 
 
 
 return 0;
 }
Solution
Note :- No need to write code for each and every time put in a loop it run it 16 times . In below code the computer need to give hexadecimal values dynamically it very reduce the complexity of an program and it is more efficient then the static code.
Solution :-
#include <stdio.h>
 #include <math.h>
 #include <string.h>
 #include<malloc.h>
int main()
 {
 char hex[17];
 long long decimal, place;
 int i = 0, val, len,tp=0,d,k;
decimal = 0;
 place = 1;
 for(k=1;k<=16;k++)
 {
 printf(\"Round %d in progress....!\ \",k);
 printf(\"Enter any hexadecimal number: \");
 scanf(\"%s\",&hex);
 /* Finds the length of total number of hex digit */
 len = strlen(hex);
 len--;
/*
 * Converts the hexadecimal number to decimal number
 * using algorithm decimal = decimal + (hex[i] * 16 ^ digit)
 */
 for(i=0; hex[i]!=\'\\0\'; i++)
 {
 /*
 * Finds the decimal each equivalent hexadecimal digit
 */
 switch(hex[i])
 {
 case \'0\':
 val = 0;
 break;
 case \'1\':
 val = 1;
 break;
 case \'2\':
 val = 2;
 break;
 case \'3\':
 val = 3;
 break;
 case \'4\':
 val = 4;
 break;
 case \'5\':
 val = 5;
 break;
 case \'6\':
 val = 6;
 break;
 case \'7\':
 val = 7;
 break;
 case \'8\':
 val = 8;
 break;
 case \'9\':
 val = 9;
 break;
 case \'a\':
 case \'A\':
 val = 10;
 break;
 case \'b\':
 case \'B\':
 val = 11;
 break;
 case \'c\':
 case \'C\':
 val = 12;
 break;
 case \'d\':
 case \'D\':
 val = 13;
 break;
 case \'e\':
 case \'E\':
 val = 14;
 break;
 case \'f\':
 case \'F\':
 val = 15;
 break;
 }
decimal += val * pow(16, len);
 len--;
 }
 printf(\"Enter it\'s Equvelent Decimal Value :- \");
 scanf(\"%d\",&d);
 if(d==decimal)
 {
 printf(\"Great job you have won 16 points \ \");
 tp=tp+16;
 printf(\"Total points after Round %d are :- %d\ \",k,tp);
 }
 else
 {
 printf(\"Sorry wrong answer! Correct answer is %d, but nice try! \ \",decimal);
 tp=tp-16;
 printf(\"Total points after Round %d : %d\ \",k,tp);
 }
 decimal=0;
 }
return 0;
 }
OUTPUT :-
Round 1 in progress....!
Enter any hexadecimal number: 1a
 Enter it\'s Equvelent Decimal Value :- 26
 Great job you have won 16 points
 Total points after Round 1 are :- 16
 Round 2 in progress....!
 Enter any hexadecimal number: 3d
 Enter it\'s Equvelent Decimal Value :- 65
 Sorry wrong answer! Correct answer is 61, but nice try!
 Total points after Round 2 : 0
 Round 3 in progress....!
 Enter any hexadecimal number: 5b
 Enter it\'s Equvelent Decimal Value :- 91
 Great job you have won 16 points
 Total points after Round 3 are :- 16
 Round 4 in progress....!
 Enter any hexadecimal number: 5d
 Enter it\'s Equvelent Decimal Value :- 93
 Great job you have won 16 points
 Total points after Round 4 are :- 32
 Round 5 in progress....!
 Enter any hexadecimal number: 78
 Enter it\'s Equvelent Decimal Value :- 120
 Great job you have won 16 points
 Total points after Round 5 are :- 48
 Round 6 in progress....!
 Enter any hexadecimal number: f6
 Enter it\'s Equvelent Decimal Value :- 246
 Great job you have won 16 points
 Total points after Round 6 are :- 64
 Round 7 in progress....!
 Enter any hexadecimal number: 23
 Enter it\'s Equvelent Decimal Value :- 35
 Great job you have won 16 points
 Total points after Round 7 are :- 80
 Round 8 in progress....!
 Enter any hexadecimal number: e6
 Enter it\'s Equvelent Decimal Value :- 232
 Sorry wrong answer! Correct answer is 230, but nice try!
 Total points after Round 8 : 64
 Round 9 in progress....!
 Enter any hexadecimal number: f3
 Enter it\'s Equvelent Decimal Value :- 255
 Sorry wrong answer! Correct answer is 243, but nice try!
 Total points after Round 9 : 48
 Round 10 in progress....!
 Enter any hexadecimal number: 7f
 Enter it\'s Equvelent Decimal Value :- 127
 Great job you have won 16 points
 Total points after Round 10 are :- 64
 Round 11 in progress....!
 Enter any hexadecimal number: 1d
 Enter it\'s Equvelent Decimal Value :- 22
 Sorry wrong answer! Correct answer is 29, but nice try!
 Total points after Round 11 : 48
 Round 12 in progress....!
 Enter any hexadecimal number: e3
 Enter it\'s Equvelent Decimal Value :- 226
 Sorry wrong answer! Correct answer is 227, but nice try!
 Total points after Round 12 : 32
 Round 13 in progress....!
 Enter any hexadecimal number: 4f
 Enter it\'s Equvelent Decimal Value :- 79
 Great job you have won 16 points
 Total points after Round 13 are :- 48
 Round 14 in progress....!
 Enter any hexadecimal number: 9d
 Enter it\'s Equvelent Decimal Value :- 157
 Great job you have won 16 points
 Total points after Round 14 are :- 64
 Round 15 in progress....!
 Enter any hexadecimal number: 7a
 Enter it\'s Equvelent Decimal Value :- 122
 Great job you have won 16 points
 Total points after Round 15 are :- 80
 Round 16 in progress....!
 Enter any hexadecimal number: 3a
 Enter it\'s Equvelent Decimal Value :- 58
 Great job you have won 16 points
 Total points after Round 16 are :- 96
I hope it wil more help full to you by this code you can modify as a two players game also.







