Hey, i was just going to start making a game where srand made a random number between 1&99 and that is the power you would hit of someone else, the one to defeat the other person won,

I got some prefix errors etc :

#include <conio.h>
#include <iostream>

using namespace std;

int main()
{
    int 1attack, 2attack, 1hp, 2hp;
    char attack;
    
    cout << "Player 1, Press 'A' to attack : ";
    cin >> attack;
    
    switch(attack)
    {
                      
    case 'a':
    case 'A': 
         srand ( time(NULL) );
         1attack = rand() % 99 + 1; 
         cout << "You hit " << 1attack << "!";
    break;
    
    case default:
         cout << endl << "INVALID SELECTION!";
    break;
    }
    getch();
}

I was going to put this on to ask for help with how to do things with the game so i'll leave this thread for help with the errors and maybe some help with the game :)?

Line 24, it just default, not case default

default:
         cout << endl << "INVALID SELECTION!";
    break;

And you cannot declare variables starting with numeral. Try this

int attack, attack2, hp2, hp;

i still get:
invalid suffix
expected ; before int

Then you most probably still use there a variable whose name starts with a digit, so please double-check the code.

Call srand() just ONCE at the start of the program, not every time you want a rand().

At best, it achieves nothing. At worst, it prompts "Why does rand() always return the same value" questions on the message boards.

Thanky you for poiting out the variable parts, now for the game bit, would i use a while loop for when the hp is > 0?

This article has been dead for over six months. Start a new discussion instead.