Hello!
I have a big problem. In visual C++ I can create a program that functions perfectly like this when I create a windows32 application empty program and add a cpp file to source files in visual c++ 2008
// 'Hello World!' program
BUT whenever I try to run this program the same way it says "Unable to find...(information about files).../Debug/Ogresvsdwarfs.exe"
"The system cannot find the file specified.
I'm pretty sure there is not a problem with the code but maybe in the way that i created it? Anyway here's the code...
// Ogres Vs Dwarves.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include <iostream>
#include <time.h>
#include <string>
#include <cstdlib>
using namespace std;
class Dwarves
{
public:
int speed;
int strength;
int number;
} Dwarf[3]; // make 3 sets - 1 for each battle
class Ogre
{
public:
int speed1;
int strength1;
int number1;
} Ogres[3]; // make 3 sets - 1 for each battle
void fight(int);
int round;
char answer ;
int main()
{
time_t t;
srand((unsigned) time(&t));
int a;
for (a=0;a<3;a++) // loop to give each variable a separate value
{
Dwarf[a].speed = 1+rand()%20; // change these 6 rands() to what you needed
Dwarf[a].strength = 1+rand()%75;
Dwarf[a].number = 1+rand()%10;
Ogres[a].speed1 = 1+rand()%20;
Ogres[a].strength1 = 1+rand()%75;
Ogres[a].number1 = 1+rand()%10;
}
cout << "The Dwarfs and Ogres are about to fight for three rounds!\n";
for(round = 0; round < 3; round++)
{
answer = 'n';
while( answer !='Y' && answer !='y')
{
cout << "Are you ready to fight! y or n : ";
cin >> answer; // must press 'y' to continue
}
cout << "Round #" << round+1 << "\n\n"; // Shows stats before the battle
cout << "Here are the stats...\n";
cout << "DWARFS :\n";
cout << "speed = " << Dwarf[round].speed << "\n";
cout << "strength = " << Dwarf[round].strength << "\n";
cout << "number of Dwarves = " << Dwarf[round].number << "\n";
cout << "OGRES : \n";
cout << "speed = " << Ogres[round].speed1 << "\n";
cout << "strength = " << Ogres[round].strength1 << "\n";
cout << "number of Ogres = " << Ogres[round].number1 << "\n\n";
cout << "The winner of this battle, were ";
fight(round); // sends round # to function.
}
return 0;
}
void fight(int round)
{
string winner = "";
int dwarfpower = Dwarf[round].speed + Dwarf[round].strength + Dwarf[round].number;
int ogrepower = Ogres[round].speed1 + Ogres[round].strength1 + Ogres[round].number1;
if(dwarfpower > ogrepower) // Determines Winner
winner = "the Dwarves.\n\n";
else
winner = "the Ogres.\n\n";
cout << winner; // Prints result
}
Please tell me why it isn't working because I have no clue!
@whitenite i tried to pm you but it said you didn't accept pms. So i started a new topic. But your help would be much more appreciated after how kindly you commented on my last post :) Also when I posted that I was away from my computer so couldn't try it. But it doesn't produce errors except this one anymore
1) Hi-lite the cpp text on this page
2) Start Visual C++ 2008 Express
3) In the menu, go to 'File', then 'New', then 'Project'
4) Use 'Win32 Console Application'
5) Give it a name, like 'Ogres Vs Dwarves', press Enter
6) Click on Finish
7) In the project that opens, paste the cpp file, leaving nothing else that was there.
8) In the Menu, go to 'Debug', then to 'Start without Debugging'
Hopefully, that will let it compile without any problems.
I changed my user cp, to allow messages, now. I didn't really know that was an option before.
Thank you whitenite1 I have tested it now and it works perfectly! My problem was that I had started with a empty project but now it plays. Once again, thankyou very much.