• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

C++ C++ Game over screen

fsfsa

New Coder
Hi, I'm trying to do a game over screen for a survival game I'm creating in my high school intro to programming class, but I can't seem to get the loop to end.Once it says game over it moves on to the next section. I also want to add an option to play again. Here is a part of my project as an examaple. I'm still new to coding so I'm not sure how to do this-please help.

C++:
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <stdlib.h>
#include <windows.h>
#include<conio.h>
#include<dos.h>


using namespace std;


void SetWindow (int Width, int Height);
int GetFontSize(HANDLE windowHandle, COORD *size);
int SetFontSize (HANDLE windowHandle, COORD size);
 void gameOverscreen();
char charName;
char lastName;
int main()
{
if (color == "Red" || color == "red")
 {
     cout << "Good choice. These are tasty and safe" << endl;
 }

 else if (color == "purple" ||color == "Purple")
 {
     cout << "oh no, These were poisonous. YOU'RE DEAD";

          gameOverscreen();


                cout << "*****Game Over*****\n";

          }

 else if (color == "Black" || color == "black")
 {
     cout << "Good choice. These are exotic and safe" << endl;
 }
cout << " The dome is loaded with more supplies " << endl;
cout << "Would you like to use your map to find the dome?       "<< endl;

  return 0;
}


    void gameOverscreen()
    {
    cout << "*****Game Over*****\n";
    }
 

BGB

King Coder
Staff Team
Guardian
C++:
#include <iostream>

int main() {
    std::string color;
    std::cout << "Select from, Red, Purple, Black" << std::endl;
    std::cin >> color;
    
    if(color == "Red" | color == "red")
    {
        std::cout << "Good choice. These are tasty and safe" << std::endl;
    }
    else if(color == "Purple" | color == "purple")
    {
        std::cout << "*****Game Over*****" << std::endl;
    }
    else if(color == "Black" | color == "black")
    {
        std::cout << "Good choice. These are exotic and safe" << std::endl;
    }
    
    std::cout << "The dome is loaded with more supplies " << std::endl;
    std::cout << "Would you like to use your map to find the dome?"<< std::endl;

    return 0;
}
 
Top