What's new

Closed Need help optimizing your program code? pasok!

Status
Not open for further replies.
Sir pwede maka hingi ng ng array na babasahin medyo naguguluhan ako kasi ako.
Nagawa mo na di ba? Tandaan mo lahat ng mga natutunan mo.


Code:
String[][] easyQuestions = {
      {"Question 1", "Choice1", Choice2", Choice3", Choice4", "Answer"},
      {"Question 2", "Choice1", Choice2", Choice3", Choice4", "Answer"},
      {"Question 3", "Choice1", Choice2", Choice3", Choice4", "Answer"},
};
 
I Want to connect End() and Mainmenu()
In the functionname END() I will call MAINMENU2(). Then Inside MAINMENU2(), I Will Call Mainmenu1(). Inside Mainmenu1(), I Will call Mainmenu()But the error is the 3 functionname() identifier not found.

any suggestion master :D Hehehe
 

Attachments

Hindi ko mabasa sana ipost mo yung mismong code.
Kailangan mo siguro maglagay ng function declaration sa pinakataas after ng mga using namespace;

void MainMenu();
void MainMenu1();
void MainMenu2();
void End();

tapos ilagay mo na yung may code.
void MainMenu()
{
code;
}
.
.
.
void End()
{
code;
}
 
Kailangan mo siguro maglagay ng function declaration sa pinakataas after ng mga using namespace;

void MainMenu();
void MainMenu1();
void MainMenu2();
void End();

tapos ilagay mo na yung may code.
void MainMenu()
{
code;
}
.
.
.
void End()
{
code;
}
I mean po yung function bridge po. kasi marami na kasing lines di na niya abot yung call nang mainmenu. hehe
 
Kailangan mo siguro maglagay ng function declaration sa pinakataas after ng mga using namespace;

void MainMenu();
void MainMenu1();
void MainMenu2();
void End();

tapos ilagay mo na yung may code.
void MainMenu()
{
code;
}
.
.
.
void End()
{
code;
}
na line 21 yung End() the nasa line 2845 po yung mainmenu() haha
 
na line 21 yung End() the nasa line 2845 po yung mainmenu() haha
Yun nga baka wala kang function declarations.
Hindi alam ng mga nasa unang function na may nageexist na function na ganito kasi nasa latter part sila ng code.
MAglagay ka ng function declaration.
 
Yun nga baka wala kang function declarations.
Hindi alam ng mga nasa unang function na may nageexist na function na ganito kasi nasa latter part sila ng code.
MAglagay ka ng function declaration.
line 15: void end()
{
mainmenu4();
}

line604: void mainmenu4()
{
mainmenu3();
}
line 1045: void mainmenu3();
{
mainmenu2();
}
line 2100: void mainmenu2();
{
mainmenu();
}


line 2448 :void mainmenu()
{
cout << "......." << endl;
}
 
line 15: void end()
{
mainmenu4();
}

line604: void mainmenu4()
{
mainmenu3();
}
line 1045: void mainmenu3();
{
mainmenu2();
}
line 2100: void mainmenu2();
{
mainmenu();
}


line 2448 :void mainmenu()
{
cout << "......." << endl;
}
Ay ang kulit? Hahaha! Hind matawag ni end() si mainmenu4() kasi nasa baba niya yung code.
Hindi matawag ni mainmenu4() si mainmenu3() kasi nasa baba niya yung mainmenu3().
So on and so forth? nakuha mo na?

FUNCTION DECLARATION KAILANGAN MO.
 
Ay ang kulit? Hahaha! Hind matawag ni end() si mainmenu4() kasi nasa baba niya yung code.
Hindi matawag ni mainmenu4() si mainmenu3() kasi nasa baba niya yung mainmenu3().
So on and so forth? nakuha mo na?
Ahhhhhh Sorry po. Gets ko na sir hahahaa
 
Ay ang kulit? Hahaha! Hind matawag ni end() si mainmenu4() kasi nasa baba niya yung code.
Hindi matawag ni mainmenu4() si mainmenu3() kasi nasa baba niya yung mainmenu3().
So on and so forth? nakuha mo na?
THank You so much sir. malapit na matpos yung game haahha
 
Sir ano po yung way para ma avoid ang repitition ng randomNumber?
Kawawa ka naman. Paulit ulit nalang yang tanong mo.
Ibigay ko na sayo yung code. Palitan mo nalang yung values sa array.
Sana pag-aralan mo, para hindi ka makawawa kapag pinakita mo yan sa class.


Code:
#include <iostream>
#include <cstdlib>
#include <stdlib.h>
#include <time.h>
using namespace std;


int life = 3;
int removeChoices = 3;
string answer = "";
   
void ShowFiveQuestion(string questions[][6]);
void ShowQuestionWithTwoChoices(string questions[][6], int a, int b);
void ShowIdentification(string questions[][2]);

int main()
{
        string easyQuestions[15][6] =
    {
        {"Question 1", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
        {"Question 2", "Choice 1", "Choice 2", "Answer", "Choice 4", "Answer"},
        {"Question 3", "Answer", "Choice 2", "Choice 3", "Choice 4", "Answer"},
        {"Question 4", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
        {"Question 5", "Answer", "Choice 2", "Choice 3", "Choice 4", "Answer"},
        {"Question 6", "Choice 1", "Choice 2", "Choice 3", "Answer", "Answer"},
        {"Question 7", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
        {"Question 8", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
        {"Question 9", "Choice 1", "Choice 2", "Answer", "Choice 4", "Answer"},
        {"Question 10", "Answer", "Choice 2", "Choice 3", "Choice 4", "Answer"},
        {"Question 11", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
        {"Question 12", "Choice 1", "Choice 2", "Answer", "Choice 4", "Answer"},
        {"Question 13", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
        {"Question 14", "Answer", "Choice 2", "Choice 3", "Choice 4", "Answer"},
        {"Question 15", "Choice 1", "Choice 2", "Choice 3", "Answer", "Answer"}
    };
    string mediumQuestions[15][6] =
    {
        {"Question 1", "Answer", "Choice 2", "Choice 3", "Choice 4", "Answer"},
        {"Question 2", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
        {"Question 3", "Choice 1", "Choice 2", "Answer", "Choice 4", "Answer"},
        {"Question 4", "Choice 1", "Choice 2", "Choice 3", "Answer", "Answer"},
        {"Question 5", "Choice 1", "Choice 2", "Answer", "Choice 4", "Answer"},
        {"Question 6", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
        {"Question 7", "Answer", "Choice 2", "Choice 3", "Choice 4", "Answer"},
        {"Question 8", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
        {"Question 9", "Choice 1", "Choice 2", "Answer", "Choice 4", "Answer"},
        {"Question 10", "Choice 1", "Choice 2", "Choice 3", "Answer", "Answer"},
        {"Question 11", "Choice 1", "Choice 2", "Answer", "Choice 4", "Answer"},
        {"Question 12", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
        {"Question 13", "Answer", "Choice 2", "Choice 3", "Choice 4", "Answer"},
        {"Question 14", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
        {"Question 15", "Choice 1", "Choice 2", "Answer", "Choice 4", "Answer"}
    };
    string hardQuestions[15][6] =
    {
        {"Question 1", "Answer", "Choice 2", "Choice 3", "Choice 4", "Answer"},
        {"Question 2", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
        {"Question 3", "Choice 1", "Choice 2", "Answer", "Choice 4", "Answer"},
        {"Question 4", "Choice 1", "Choice 2", "Answer", "Choice 4", "Answer"},
        {"Question 5", "Choice 1", "Choice 2", "Choice 3", "Answer", "Answer"},
        {"Question 6", "Choice 1", "Choice 2", "Choice 3", "Answer", "Answer"},
        {"Question 7", "Choice 1", "Choice 2", "Answer", "Choice 4", "Answer"},
        {"Question 8", "Choice 1", "Choice 2", "Answer", "Choice 4", "Answer"},
        {"Question 9", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
        {"Question 10", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
        {"Question 11", "Answer", "Choice 2", "Choice 3", "Choice 4", "Answer"},
        {"Question 12", "Answer", "Choice 2", "Choice 3", "Choice 4", "Answer"},
        {"Question 13", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
        {"Question 14", "Choice 1", "Choice 2", "Answer", "Choice 4", "Answer"},
        {"Question 15", "Choice 1", "Choice 2", "Choice 3", "Answer", "Answer"}
    };
    string identification[15][2] =
    {
        {"Question 1", "Answer"},
        {"Question 2", "Answer"},
        {"Question 3", "Answer"},
        {"Question 4", "Answer"},
        {"Question 5", "Answer"},
        {"Question 6", "Answer"},
        {"Question 7", "Answer"},
        {"Question 8", "Answer"},
        {"Question 9", "Answer"},
        {"Question 10", "Answer"},
        {"Question 11", "Answer"},
        {"Question 12", "Answer"},
        {"Question 13", "Answer"},
        {"Question 14", "Answer"},
        {"Question 15", "Answer"}
    };
   
    if(life > 0)
    {
        cout<< "Round 1: Easy\n";
        ShowFiveQuestion(easyQuestions);
    }
    if(life > 0)
    {
        cout<< "Round 2: Medium\n";
        ShowFiveQuestion(mediumQuestions);
    }
    if(life > 0)
    {
        cout<< "Round 3: Hard\n";
        ShowFiveQuestion(hardQuestions);
    }
    if(life > 0)
    {
        cout<<"Last round: Identification\n";
        ShowIdentification(identification);
    }

    return 0;
}
void ShowIdentification(string questions[][2])
{
    srand (time(NULL));
    int randomNumber;
    int shownQuestion[5] = {0, 0, 0, 0, 0};
    bool shown = false;
    int totalQuestion = 0;
    string playerAnswer = "";
   
    while(totalQuestion < 5)
    {
        randomNumber = rand() % 15;
         //Check if shown
        for(int j = 0; j < 5; j++)
        {
            if(shownQuestion[j] == randomNumber)
            {
                shown = true;
                break;
            }
        }
        if(!shown && life > 0)
        {
            cout<< "Life: " << life << endl;
            cout<< "Question [" << totalQuestion + 1 << "/5]: " << questions[randomNumber][0] << endl << endl;
            cout<< "Answer: ";
            cin >> answer;
           
            if(answer == questions[randomNumber][1])
            {
                cout<< "Correct!\n\n";
                cin.get();
                cin.get();
                system("clear");
            }
            else
            {
                cout<< "Incorrect, life is deducted...\n\n";
                life--;
                cin.get();
                cin.get();
                system("clear");

            }
            shownQuestion[totalQuestion] = randomNumber;
            totalQuestion++;
        }
        else if (life == 0)
        {
            cout<< "Game Over!\n";
            break;
        }
        shown = false;
    }
    if(life > 0)
    {
        cout<< "Congratulations! You WIN!!!";
        cin.get();
    }
   
    system("clear");
}
void ShowFiveQuestion(string questions[][6])
{
    srand (time(NULL));
    int randomNumber;
    int shownQuestion[5] = {0, 0, 0, 0, 0};
    bool shown = false;
    int totalQuestion = 0;
    int choices = 0;
    while(totalQuestion < 5)
    {
        randomNumber = rand() % 15;
         //Check if shown
        for(int j = 0; j < 5; j++)
        {
            if(shownQuestion[j] == randomNumber)
            {
                shown = true;
                break;
            }
        }
        if(!shown && life > 0)
        {
            while(true)
            {
                cout<< "Life: " << life << " Help: " << removeChoices << endl;
                cout<< "Question [" << totalQuestion + 1 << "/5]: " << questions[randomNumber][0] << endl << endl;
                cout<< "Choices: [A] " << questions[randomNumber][1] << endl;
                cout<< "Choices: [B] " << questions[randomNumber][2] << endl;
                cout<< "Choices: [C] " << questions[randomNumber][3] << endl;
                cout<< "Choices: [D] " << questions[randomNumber][4] << endl << endl;
                cout<< "Answer (Type 'H', if you want to remove 2 incorrect choices): ";
                cin >> answer;

                if(answer == "H" && removeChoices > 0)
                {
                    removeChoices--;
                    system("clear");
                    ShowQuestionWithTwoChoices(questions, randomNumber, totalQuestion);
                    break;
                }
                else if(answer == "H" && removeChoices == 0)
                {
                    cout<< "You can't remove choices anymore... Try again...\n";
                    cin.get();
                    cin.get();
                    system("clear");
                }
                else if(answer == "A")
                {
                    answer = questions[randomNumber][1];
                    break;
                }
                else if(answer == "B")
                {
                    answer = questions[randomNumber][2];
                    break;
                }
                else if(answer == "C")
                {
                    answer = questions[randomNumber][3];
                    break;
                }
                else if(answer == "D")
                {
                    answer = questions[randomNumber][4];
                    break;
                }
            }
            if(answer == questions[randomNumber][5])
            {
                cout<< "Correct!\n\n";
                cin.get();
                cin.get();
                system("clear");
            }
            else
            {
                cout<< "Incorrect, life is deducted...\n\n";
                life--;
                cin.get();
                cin.get();
                system("clear");

            }
            shownQuestion[totalQuestion] = randomNumber;
            totalQuestion++;
        }
        else if (life == 0)
        {
            cout<< "Game Over!";
            break;
        }
        shown = false;
    }
    if(life > 0)
    {
        cout<< "Congratulations! You passed this round. Next round!";
        cin.get();
    }
   
    system("clear");
}

void ShowQuestionWithTwoChoices(string questions[][6], int a, int b)
{
    string incorrectChoice = "";
    int r = 0;
    while(incorrectChoice == "")
    {
        r = rand() % 5 + 1;
        if(questions[a][r] != questions[a][5])
        {
            incorrectChoice = questions[a][r];
        }
    }
   
    r = rand() % 2;
   
    cout<< "Life: " << life << endl;
    cout<< "Question [" << b + 1 << "/5]: " << questions[a][0] << endl << endl;
   
    if(r == 1)
    {
        cout<< "Choice [A]: " << incorrectChoice << endl;
        cout<< "Choice [B]: " << questions[a][5] << endl;
        cout<< "Answer : ";
        cin >> answer;
        if(answer == "A")
        {
            answer = incorrectChoice;
        }
        else if(answer == "B")
        {
            answer = questions[a][5];
        }
    }
    else if(r == 0)
    {
        cout<< "Choice [A]: " << questions[a][5] << endl;
        cout<< "Choice [B]: " << incorrectChoice << endl;
        cout<< "Answer : ";
        cin >> answer;
        if(answer == "A")
        {
            answer = questions[a][5];
        }
        else if(answer == "B")
        {
            answer = incorrectChoice;
        }
    }
}
 
Kawawa ka naman. Paulit ulit nalang yang tanong mo.
Ibigay ko na sayo yung code. Palitan mo nalang yung values sa array.
Sana pag-aralan mo, para hindi ka makawawa kapag pinakita mo yan sa class.


Code:
#include <iostream>
#include <cstdlib>
#include <stdlib.h>
#include <time.h>
using namespace std;


int life = 3;
int removeChoices = 3;
string answer = "";
  
void ShowFiveQuestion(string questions[][6]);
void ShowQuestionWithTwoChoices(string questions[][6], int a, int b);
void ShowIdentification(string questions[][2]);

int main()
{
        string easyQuestions[15][6] =
    {
        {"Question 1", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
        {"Question 2", "Choice 1", "Choice 2", "Answer", "Choice 4", "Answer"},
        {"Question 3", "Answer", "Choice 2", "Choice 3", "Choice 4", "Answer"},
        {"Question 4", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
        {"Question 5", "Answer", "Choice 2", "Choice 3", "Choice 4", "Answer"},
        {"Question 6", "Choice 1", "Choice 2", "Choice 3", "Answer", "Answer"},
        {"Question 7", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
        {"Question 8", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
        {"Question 9", "Choice 1", "Choice 2", "Answer", "Choice 4", "Answer"},
        {"Question 10", "Answer", "Choice 2", "Choice 3", "Choice 4", "Answer"},
        {"Question 11", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
        {"Question 12", "Choice 1", "Choice 2", "Answer", "Choice 4", "Answer"},
        {"Question 13", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
        {"Question 14", "Answer", "Choice 2", "Choice 3", "Choice 4", "Answer"},
        {"Question 15", "Choice 1", "Choice 2", "Choice 3", "Answer", "Answer"}
    };
    string mediumQuestions[15][6] =
    {
        {"Question 1", "Answer", "Choice 2", "Choice 3", "Choice 4", "Answer"},
        {"Question 2", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
        {"Question 3", "Choice 1", "Choice 2", "Answer", "Choice 4", "Answer"},
        {"Question 4", "Choice 1", "Choice 2", "Choice 3", "Answer", "Answer"},
        {"Question 5", "Choice 1", "Choice 2", "Answer", "Choice 4", "Answer"},
        {"Question 6", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
        {"Question 7", "Answer", "Choice 2", "Choice 3", "Choice 4", "Answer"},
        {"Question 8", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
        {"Question 9", "Choice 1", "Choice 2", "Answer", "Choice 4", "Answer"},
        {"Question 10", "Choice 1", "Choice 2", "Choice 3", "Answer", "Answer"},
        {"Question 11", "Choice 1", "Choice 2", "Answer", "Choice 4", "Answer"},
        {"Question 12", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
        {"Question 13", "Answer", "Choice 2", "Choice 3", "Choice 4", "Answer"},
        {"Question 14", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
        {"Question 15", "Choice 1", "Choice 2", "Answer", "Choice 4", "Answer"}
    };
    string hardQuestions[15][6] =
    {
        {"Question 1", "Answer", "Choice 2", "Choice 3", "Choice 4", "Answer"},
        {"Question 2", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
        {"Question 3", "Choice 1", "Choice 2", "Answer", "Choice 4", "Answer"},
        {"Question 4", "Choice 1", "Choice 2", "Answer", "Choice 4", "Answer"},
        {"Question 5", "Choice 1", "Choice 2", "Choice 3", "Answer", "Answer"},
        {"Question 6", "Choice 1", "Choice 2", "Choice 3", "Answer", "Answer"},
        {"Question 7", "Choice 1", "Choice 2", "Answer", "Choice 4", "Answer"},
        {"Question 8", "Choice 1", "Choice 2", "Answer", "Choice 4", "Answer"},
        {"Question 9", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
        {"Question 10", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
        {"Question 11", "Answer", "Choice 2", "Choice 3", "Choice 4", "Answer"},
        {"Question 12", "Answer", "Choice 2", "Choice 3", "Choice 4", "Answer"},
        {"Question 13", "Choice 1", "Answer", "Choice 3", "Choice 4", "Answer"},
        {"Question 14", "Choice 1", "Choice 2", "Answer", "Choice 4", "Answer"},
        {"Question 15", "Choice 1", "Choice 2", "Choice 3", "Answer", "Answer"}
    };
    string identification[15][2] =
    {
        {"Question 1", "Answer"},
        {"Question 2", "Answer"},
        {"Question 3", "Answer"},
        {"Question 4", "Answer"},
        {"Question 5", "Answer"},
        {"Question 6", "Answer"},
        {"Question 7", "Answer"},
        {"Question 8", "Answer"},
        {"Question 9", "Answer"},
        {"Question 10", "Answer"},
        {"Question 11", "Answer"},
        {"Question 12", "Answer"},
        {"Question 13", "Answer"},
        {"Question 14", "Answer"},
        {"Question 15", "Answer"}
    };
  
    if(life > 0)
    {
        cout<< "Round 1: Easy\n";
        ShowFiveQuestion(easyQuestions);
    }
    if(life > 0)
    {
        cout<< "Round 2: Medium\n";
        ShowFiveQuestion(mediumQuestions);
    }
    if(life > 0)
    {
        cout<< "Round 3: Hard\n";
        ShowFiveQuestion(hardQuestions);
    }
    if(life > 0)
    {
        cout<<"Last round: Identification\n";
        ShowIdentification(identification);
    }

    return 0;
}
void ShowIdentification(string questions[][2])
{
    srand (time(NULL));
    int randomNumber;
    int shownQuestion[5] = {0, 0, 0, 0, 0};
    bool shown = false;
    int totalQuestion = 0;
    string playerAnswer = "";
  
    while(totalQuestion < 5)
    {
        randomNumber = rand() % 15;
         //Check if shown
        for(int j = 0; j < 5; j++)
        {
            if(shownQuestion[j] == randomNumber)
            {
                shown = true;
                break;
            }
        }
        if(!shown && life > 0)
        {
            cout<< "Life: " << life << endl;
            cout<< "Question [" << totalQuestion + 1 << "/5]: " << questions[randomNumber][0] << endl << endl;
            cout<< "Answer: ";
            cin >> answer;
          
            if(answer == questions[randomNumber][1])
            {
                cout<< "Correct!\n\n";
                cin.get();
                cin.get();
                system("clear");
            }
            else
            {
                cout<< "Incorrect, life is deducted...\n\n";
                life--;
                cin.get();
                cin.get();
                system("clear");

            }
            shownQuestion[totalQuestion] = randomNumber;
            totalQuestion++;
        }
        else if (life == 0)
        {
            cout<< "Game Over!\n";
            break;
        }
        shown = false;
    }
    if(life > 0)
    {
        cout<< "Congratulations! You WIN!!!";
        cin.get();
    }
  
    system("clear");
}
void ShowFiveQuestion(string questions[][6])
{
    srand (time(NULL));
    int randomNumber;
    int shownQuestion[5] = {0, 0, 0, 0, 0};
    bool shown = false;
    int totalQuestion = 0;
    int choices = 0;
    while(totalQuestion < 5)
    {
        randomNumber = rand() % 15;
         //Check if shown
        for(int j = 0; j < 5; j++)
        {
            if(shownQuestion[j] == randomNumber)
            {
                shown = true;
                break;
            }
        }
        if(!shown && life > 0)
        {
            while(true)
            {
                cout<< "Life: " << life << " Help: " << removeChoices << endl;
                cout<< "Question [" << totalQuestion + 1 << "/5]: " << questions[randomNumber][0] << endl << endl;
                cout<< "Choices: [A] " << questions[randomNumber][1] << endl;
                cout<< "Choices: [B] " << questions[randomNumber][2] << endl;
                cout<< "Choices: [C] " << questions[randomNumber][3] << endl;
                cout<< "Choices: [D] " << questions[randomNumber][4] << endl << endl;
                cout<< "Answer (Type 'H', if you want to remove 2 incorrect choices): ";
                cin >> answer;

                if(answer == "H" && removeChoices > 0)
                {
                    removeChoices--;
                    system("clear");
                    ShowQuestionWithTwoChoices(questions, randomNumber, totalQuestion);
                    break;
                }
                else if(answer == "H" && removeChoices == 0)
                {
                    cout<< "You can't remove choices anymore... Try again...\n";
                    cin.get();
                    cin.get();
                    system("clear");
                }
                else if(answer == "A")
                {
                    answer = questions[randomNumber][1];
                    break;
                }
                else if(answer == "B")
                {
                    answer = questions[randomNumber][2];
                    break;
                }
                else if(answer == "C")
                {
                    answer = questions[randomNumber][3];
                    break;
                }
                else if(answer == "D")
                {
                    answer = questions[randomNumber][4];
                    break;
                }
            }
            if(answer == questions[randomNumber][5])
            {
                cout<< "Correct!\n\n";
                cin.get();
                cin.get();
                system("clear");
            }
            else
            {
                cout<< "Incorrect, life is deducted...\n\n";
                life--;
                cin.get();
                cin.get();
                system("clear");

            }
            shownQuestion[totalQuestion] = randomNumber;
            totalQuestion++;
        }
        else if (life == 0)
        {
            cout<< "Game Over!";
            break;
        }
        shown = false;
    }
    if(life > 0)
    {
        cout<< "Congratulations! You passed this round. Next round!";
        cin.get();
    }
  
    system("clear");
}

void ShowQuestionWithTwoChoices(string questions[][6], int a, int b)
{
    string incorrectChoice = "";
    int r = 0;
    while(incorrectChoice == "")
    {
        r = rand() % 5 + 1;
        if(questions[a][r] != questions[a][5])
        {
            incorrectChoice = questions[a][r];
        }
    }
  
    r = rand() % 2;
  
    cout<< "Life: " << life << endl;
    cout<< "Question [" << b + 1 << "/5]: " << questions[a][0] << endl << endl;
  
    if(r == 1)
    {
        cout<< "Choice [A]: " << incorrectChoice << endl;
        cout<< "Choice [B]: " << questions[a][5] << endl;
        cout<< "Answer : ";
        cin >> answer;
        if(answer == "A")
        {
            answer = incorrectChoice;
        }
        else if(answer == "B")
        {
            answer = questions[a][5];
        }
    }
    else if(r == 0)
    {
        cout<< "Choice [A]: " << questions[a][5] << endl;
        cout<< "Choice [B]: " << incorrectChoice << endl;
        cout<< "Answer : ";
        cin >> answer;
        if(answer == "A")
        {
            answer = questions[a][5];
        }
        else if(answer == "B")
        {
            answer = incorrectChoice;
        }
    }
}
Grabe naman po. Hehe pero thank you po. Sadyang 1st year plng po ako. Com eng. bala finals po namin if di makapass sa deadline yun alam na. Gusto ko lng po matutunan if paano ying may idea kana. Katulad nung mga prev na mga question ko abou sa mga case. Sa inyo na po kasi nag sabi na dapat hindi mag dapat mag spoonfeed. Mahirap napo kunin yung binagay mo pong code kasi di pa namin yan natooic sir. Sorry. Pero thank you po sa mga turo idol :)
 
Grabe naman po. Hehe pero thank you po. Sadyang 1st year plng po ako. Com eng. bala finals po namin if di makapass sa deadline yun alam na. Gusto ko lng po matutunan if paano ying may idea kana. Katulad nung mga prev na mga question ko abou sa mga case. Sa inyo na po kasi nag sabi na dapat hindi mag dapat mag spoonfeed. Mahirap napo kunin yung binagay mo pong code kasi di pa namin yan natooic sir. Sorry. Pero thank you po sa mga turo idol :)
Ano ba ang last topic niyo? Imposible hindi niyo ma natatackle ang array.
 
Ano ba ang last topic niyo? Imposible hindi niyo ma natatackle ang array.
Bale last prefinal namin us nagprigram kame ng Triangle. Idetirmine po if anong kindss of triangles. Bale decisions sir? Yung if, else if, if. Yan sir yung yopic namin. Tbh, ngayong final lng ako nagkalaman sa programing. Hahaha the combination of analyzing and combination of tutorials sa google. Pero if di makaya yun nag tataning ako sa inyo. Hehe
 
Status
Not open for further replies.

Similar threads

Back
Top