//A Fight

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>

using namespace std;

using std::cout;
using std::endl;
using std::cin;
using std::string;

int main()
{
    char again = 'y';
    while (again == 'y')

    string yourweapon;
    cout << "Enter weapon: ";
[B][U]    cin >> yourweapon;[/U][/B]

    string yourname;
    cout << "Enter first name: ";
    cin >> yourname;

    string enemyname;
    cout << "Enter enemy name: ";
    cin >> enemyname;

    srand(time(0));

    int randomNumber = rand();

    int healthloss = (randomNumber % 200) + 1;
    cout << "You did damage " << healthloss << endl;

    {
         cout << "\n**Played a cool game**";
         cout << "\nDo you want to play again? (y/n): ";
         cin >> again;
    }
         
    cout << "\nOkay, bye.";

    return 0;
}

I am teaching myself C++ and this is my first program. the error is bolded and underlined.

No, a statement is bolded and underlined. The error is missing -- you have to post it.

It is what my compiler says. It is the error.

It is what my compiler says. It is the error.

Oh, that explains all. Then the solution is get rid of the error.

You need a better compiler that tells you what the error actually is. Get rid of the one you're using if all is says is "This is an error". You need better messages than that.

Not trying to butt in here, but I'd say that the error is on (or at least caused by) a line above the underlined one.

A while loop should include brackets like:

while(condition){//bracket goes here
     //do stuff
    
}//end loop

That is a very good information, thanks for the information, if you have more information please tell us.

Here you have the correct code:

//A Fight

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>

using namespace std;

using std::cout;
using std::endl;
using std::cin;
using std::string;

int main()
{
    char again = 'y';
	while (again == 'y') {
		string yourweapon;
		cout << "Enter weapon: ";
		cin >> yourweapon;

		string yourname;
		cout << "Enter first name: ";
		cin >> yourname;

		string enemyname;
		cout << "Enter enemy name: ";
		cin >> enemyname;
		
		srand(time(0));

		int randomNumber = rand();

		int healthloss = (randomNumber % 200) + 1;
		cout << "You did damage " << healthloss << endl;

		{
			 cout << "\n**Played a cool game**";
			 cout << "\nDo you want to play again? (y/n): ";
			 cin >> again;
		}
	}        
    cout << "\nOkay, bye.";

    return 0;
}

The while-loop was the problem here - as mentioned. Always use brackets whenever there are several statements inside the loop. :)

commented: We do NOT correct code for people. We HELP them correcet their own code. -2

Thankyou now it works. Thanks for that tip I will keep that in mind

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.