Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > C/C++
You last visited: Today at 07:23

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



load and calculate problem

Discussion on load and calculate problem within the C/C++ forum part of the Coders Den category.

Reply
 
Old   #1
 
LordGragen.'s Avatar
 
elite*gold: 0
Join Date: Dec 2012
Posts: 606
Received Thanks: 68
load and calculate problem

hey guys, so for this math game i manage to do allot but there is this 2 parts i am totally lost so if anyone can help that will be perfect

first here is the code

Code:
#include <iostream>
#include <string>
#include <stdlib.h>
#include <fstream>


using namespace std;

void addition();
void subtraction();
void multiplication();
void division();
void stats();
void quit();


void checkAnswer(int userAnswer, int realAnswer);



string userName ("");
float money (0.00f);
int correct (0), incorrect (0);

ifstream LoadFile;
ofstream outFile;

int main()
{


        cout << "************************\n" <<
                "************************\n" <<
                "************************\n" <<
                "******            ******\n" <<
                "******TheMathGame ******\n" <<
                "******    BY      ******\n" <<
                "******     Boris  ******\n" <<
                "****** Grigoryan  ******\n" <<
                "******            ******\n" <<
                "************************\n" <<
                "************************\n" <<
                "************************\n";

        cout << "\nType \"Y\" or \"y\" in order to play, any other inputs will exit.\n";

        string inputString;
        getline(cin, inputString);

        if(inputString == "y" || inputString == "Y")
        {

                system("cls");
                cout << "Whats is your name good sir?" << endl;
                getline(cin, userName);

                                if (userName == userName+".txt")
                    {
                                       
                           // if the name is the same as the text then it should load back the stats
                                  //  how many correct he got his money and the incorrect.
                    }
                                else
                                {
                                      outFile.open (userName+".txt");
                                }
                               
                while(true)
                {
                        system("cls");
                        cout << "************PICK ONE**********\n" <<
                                "******************************\n" <<
                                "******************************\n" <<
                                "******                  ******\n" <<
                                "****** 1. ADD          ******\n" <<
                                "****** 2. SUBTRACT      ******\n" <<
                                "****** 3. MULTIPLY      ******\n" <<
                                "****** 4. DIVIDE        ******\n" <<
                                "****** 5. STATS         ******\n" <<
                                "****** n/N to QUIT      ******\n" <<
                                "******                  ******\n" <<
                                "******************************\n" <<
                                "******************************\n" <<
                                "******************************\n";

                        char inputChar (0);
                        getline(cin, inputString);
                                                if (inputString.length() == 1)
                                                {
                                                        inputChar = inputString[0];
                                                }

                        switch (inputChar)
                        {
                        case '1':
                                addition();
                                break;
                        case '2':
                                subtraction();
                                break;
                        case '3':
                                multiplication();
                                break;
                        case '4':
                                division();
                                break;
                        case '5':
                                stats();
                                break;
                        case 'n':
                        case 'N':
                                quit();
                                                                return 0;
                                                                break;
                        default:
                                break;
                        }
                }
        }
        else
        {
                return 0;
        }

        return 0;
}

void addition()
{
   unsigned int X (rand() % 10 + 1), Y (rand() % 10 + 1);
   unsigned int Z (X + Y);

        system("cls");
        cout << "************ADDITION**********\n" <<
                "******************************\n" <<
                "******      "<< X <<" + "<< Y <<" =     ******\n" <<
                "******************************\n" <<
                "******************************\n";

        int answer;
        cin >> answer;

        checkAnswer(answer, Z);
}

void subtraction()
{
        int X (rand() % 20 + 11), Y (rand() % 10 + 1);
        int Z (X - Y);

        system("cls");
        cout << "**********SUBTRACTION*********\n" <<
                "******************************\n" <<
                "******      "<< X <<" - "<< Y <<" =     ******\n" <<
                "******************************\n" <<
                "******************************\n";

        int answer;
        cin >> answer;

        checkAnswer(answer, Z);
}

void multiplication()
{
        int X (rand() % 10 + 1), Y (rand() % 10 + 1);
        int Z (X * Y);

        system("cls");
        cout << "*********MULTIPLICATION*******\n" <<
                "******************************\n" <<
                "******      "<< X <<" * "<< Y <<" =     ******\n" <<
                "******************************\n" <<
                "******************************\n";

        int answer;
        cin >> answer;

        checkAnswer(answer, Z);
}

void division()
{
        int X (rand() % 20 + 11), Y (rand() % 10 + 1);
        int Z (X / Y);

        system("cls");
        cout << "************DIVISION**********\n" <<
                "******************************\n" <<
                "******      "<< X <<" / "<< Y <<" =     ******\n" <<
                "******************************\n" <<
                "******************************\n";

        int answer;
        cin >> answer;

        checkAnswer(answer, Z);
}

void stats()
{
        system("cls");
        cout << userName << "'s Stats: " << endl <<
                "Money: " << money << endl <<
                "Correct: " << correct << endl <<
                "Incorrect: " << incorrect << endl << endl <<
                "Types Something To Continue" << endl;

       
        cin.get();
}

void checkAnswer(int userAnswer, int realAnswer)
{
        system("cls");
        if (userAnswer == realAnswer)
        {
                money += 0.05f;
                correct++;
                                   
                               

                cout << "************CORRECT***********\n" <<
                        "******************************\n" <<
                        "******  Answer: "<< realAnswer <<"       ******\n" <<
                        "******************************\n" <<
                        "******************************\n";
        }
        else
        {
                money -= 0.03f;
                incorrect++;
                cout << "**************WRONG***********\n" <<
                        "******************************\n" <<
                        "******  Answer: "<< realAnswer <<"       ******\n" <<
                        "******************************\n" <<
                        "******************************\n";
        }

        cin.get();
        cin.get();
               
}

void quit()
{
        outFile << userName << "'s Stats: " << endl <<
        outFile <<   "Money: " << money << endl <<
        outFile <<     "Correct: " << correct << endl <<
        outFile <<     "Incorrect: " << incorrect << endl << endl;
            outFile.close();
         

}

now the first problem is that when the user start the game play few times he can click N or n which will close the game and save his stats. now lets say i have my text file with my name in the folder and i want to play with my old record i should be able to put the same name which will load the stats back in the program but i dont know how to do that please help me there.


the next problem i dont get is, every time you get correct answer it gives 5 cent every wrong will take 3 cent this works perfect if i am only playing add game but if lets say i play 1 add game and one subtract game the scores are getting buged.
LordGragen. is offline  
Reply


Similar Threads Similar Threads
Problem mit Save und Load
05/11/2013 - C/C++ - 7 Replies
Hey ich weiß des ist jetzt Echt Peinlich :handsdown: ich hab ein Vollfunktionierenden Hack hinbekommen mit Menü und Chams und teils anderen Kleinigkeiten aber des einzige was ich net hinbekomme ist so ein Verdammter Teleport-hack. Was ich Meine: USER klickt Save, Bewegt den Spieler, klickt Load und Tada er ist an der vorher gespeicherten Position^^ Habe meine drei Values bzw. Addressen. Die sache ist so: um X, y, oder Z rauszubekommen muss ich das hier rechnen: Playerpointer +...
[Problem] Could not load... Bitte um Hilfe
02/01/2012 - Metin2 Private Server - 0 Replies
gelöst
have some problem in attck Calculate.cs
11/16/2011 - CO2 Private Server - 7 Replies
my last problem i need fix it please Any Help at Conquer_Online_Server.Game.Attacking.Calculate.Aut oRespone(Entity attacker, Entity attacked, Int32& Damage) in D:\News\Game\Attacking\Calculate.cs:line 1206
server load up problem
01/26/2010 - Dekaron Private Server - 3 Replies
im tryin to load up my server and everything goes fine intill it goes to Building Dungeon Sectors and the dekaron server just exits out on me. anyone tell me whats happening here?? http://i698.photobucket.com/albums/vv347/inzaneki lla/error2.jpg



All times are GMT +1. The time now is 07:24.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.