locked
How do i fix these errors in my C++ source code?

    Question


  • using namespace std; int main() { int choice; int mhp, hp, i, init, atk, def, matk, mdef, hurt, mhurt, agi, magi; atk = 10; def = 15; agi = 5; matk = 10; mdef = 15; magi = 5; srand((unsigned)time(0)); init = rand()%2+1; mhp = rand()%50 + 60; hp = rand()%20 + 80; if (init == 1) { cout<<"You start.\n"; while (hp > 0 || mhp > 0) { cout<<"What do you want to do?\n1 - Fierce Attack\n2 - Lithe Attack\n3 - Defensive moves\n"; do{cin>>choice;}while(choice>3 || choice<1); switch (choice) { case 1: atk = rand()%20+10; def = rand()%10+10; agi = rand()%5; break; case 2: atk = rand()%5+10; def = rand()%10+10; agi = rand()%15; break; case 3: atk = rand()%10+10; def = rand()%20+10; agi = rand()%5; break; } choice = rand()%3; switch (choice) { case 1: matk = rand()%20+10; mdef = rand()%10+10; magi = rand()%5; break; case 2: matk = rand()%5+10; mdef = rand()%10+10; magi = rand()%15; break; case 3: matk = rand()%10+10; mdef = rand()%20+10; magi = rand()%5; break; } //Här dör folk o sÃ¥nt mhurt = (atk - magi) - (mdef/atk); if (mhurt < 0) { mhurt = 0; } mhp = mhp - mhurt; cout<<"You did "<<mhurt<<" damage to the monster!\n"; cin.get(); //Specielt här if (mhp < 1) { cout<<"You killed the beast!! You won with "<<hp<<" hp left.\n"; cin.get(); return 0; } cout<<"The monster now have "<<mhp<<" hp left.\n"; hurt = (matk - agi) - (def/matk); if (hurt < 0) { hurt = 0; } hp = hp - hurt; cout<<"The monster hit you for "<<hurt<<" damage.\n"; //Och här. if (hp < 1) { cout<<"You died. The beast still has "<<mhp<<" hp left.\n"; cin.get(); return 0; } cout<<"You now have "<<hp<<" hp left.\n\n"; } } //Om monstret startar. else { cout<<"Monster start.\n"; while (hp > 0 || mhp > 0) { choice = rand()%3; switch (choice) { case 1: matk = rand()%20+10; mdef = rand()%10+10; magi = rand()%5; break; case 2: matk = rand()%5+10; mdef = rand()%10+10; magi = rand()%15; break; case 3: matk = rand()%10+10; mdef = rand()%20+10; magi = rand()%5; break; } //Monstret börjar!! han slÃ¥r till direkt. hurt = (matk - agi) - (def/matk); if (hurt < 0) { hurt = 0; } hp = hp - hurt; cout<<"The monster hit you for "<<hurt<<" damage.\n"; //Oooooh, gotta hurt! if (hp < 1) { cout<<"You died. The beast still has "<<mhp<<" hp left.\n"; cin.get(); return 0; } cout<<"You now have "<<hp<<" hp left.\n\n"; cout<<"What do you want to do?\n1 - Fierce Attack\n2 - Lithe Attack\n3 - Defensive moves\n"; do{cin>>choice;}while(choice>3 || choice<1); switch (choice) { case 1: atk = rand()%20+10; def = rand()%10+10; agi = rand()%5; break; case 2: atk = rand()%5+10; def = rand()%10+10; agi = rand()%15; break; case 3: atk = rand()%10+10; def = rand()%20+10; agi = rand()%5; break; } //Här kan han dö. mhurt = (atk - magi) - (mdef/atk); if (mhurt < 0) { mhurt = 0; } mhp = mhp - mhurt; cout<<"You did "<<mhurt<<" damage to the monster!\n"; cin.get(); //Eller typ här: if (mhp < 1) { cout<<"You killed the beast!! You won with "<<hp<<" hp left.\n"; cin.get(); return 0; } cout<<"The monster now have "<<mhp<<" hp left.\n"; } } }

    Here are my errors/warnings:

    Error 1 error C2731: 'main' : function cannot be overloaded c:\users\marde_000\documents\visual studio 2012\projects\rpg game\rpg game\rpg game.cpp 157 1 RPG Game

    Warning 2 warning C4447: 'main' signature found without threading model. Consider using 'int main(Platform::Array<Platform::String^>^ args)'.

    I downloaded a template (in another language) and added my own information in it. Can someone give me an updated code that doesnt include these errors? Thanks in advance... :)


    Friday, August 9, 2013 3:13 AM

Answers

  • This is code for a console app, not for a Windows Store app.

    It will probably work fine in a console app project.

    If you want to learn to write games for Windows Store apps I'd stick with Windows Store app documentation and samples. If you want to do graphics then start with Get started with DirectX game development in the Developing games documentation. The GDC 2013 Windows Developer Content Direct3D Game Templates are useful but may be more advanced than you are at this point.

    You may also want to start with something simpler. If you aren't doing an action game then you may want to start looking at Xaml/C# or HTML/JavaScript. The gameplay you show here would work in either of those frameworks, but would need to be rewritten to be event-centric.

    --Rob

    Friday, August 9, 2013 8:33 PM
    Moderator