Sign in to follow this  

Pause function not working

This topic is 4107 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Alright, for some reason std::cin.get() doesn't work in EITHER codeblocks or devC++ and niether does returning from a function or something. Anyway, here is my code, I cannot for the life of me figure out where the logic problem is... main:
#include <cstdlib>

#include <iostream>

#define RANKER_VERSION "SUPER RANKING DEVICE 1.2.1 (Demo)"

//#include <stdio.h>
#include "creatures.h"
#include "item.h"



void Out(std::string a);
std::string In();
bool rSend();
bool help();
bool pause();


int main()
{
	std::cout << "Hello and welcome to the... \n \n";
	std::cout << RANKER_VERSION << "!!!!!";
    std::cout << "\n \n \n";
    std::cin.get();
    std::cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
    std::cout << "Loading......";
    ItemsData Items;
    Items.LoadItems("items.dat");
    Items.DisplayItems();
    std::string comline;
    while(comline != "quit")
    {
        std::cout << "\n Enter a command (enter 'help' for commands)";
        std::cin >> comline;
        if(comline == "help")
           {
            help();
            continue;
           }

        if(comline == "ranker")
                {
                rSend();
                continue;
                }
        std::cout << "\n That doesn't seem to be a command...";
        pause();
    }



	return 0;
}

void Out(std::string a)
{
    std::cout << a;
}

std::string In(std::string a)
{
    std::string m;
    std::cin >> m;
    return m;
}

bool rSend()
{
    int iPerc;
    int iCode;
    for(int i = 0; i > 80; i++)
    Out("/");

    Out("\n");
    Out("Welcome to the console % translator!\n");
    Out("Hopefully a windows version will be created soon\n");
    Out("Please enter your % rating\n");
    std::cin >> iPerc;
    Out("Thanks, now, if you have a special code, enter it now,\n if not, press n, then enter\n");
    std::cin >> iCode;
      std::string title;
    std::string text;
    if(iPerc == 0)
	{
        text = "You poor unstable person....";
		title = "Ha-ha!";
	}

	if(iPerc >= 1 && iPerc <= 25)
	{
		text = "How sad, you don't get a ranking.";
		title = "Ha ha ha ha, hahahahahaha";
	}

	if(iPerc >= 26 && iPerc <= 50)
	{
		text = "In my school's system, you couldn't pass the year with this";
		title = "You FAIL";
	}

	if(iPerc >= 51 && iPerc <= 60)
	{
		text = "You are a peon... NICE! \n you are in the class that gets crapped on by the others! Yay!";
		title = "Peon's RULE!";
	}

	if(iPerc >= 61 && iPerc <= 70)
	{
		text = "Congrats, you are an Underling, \n You still have miles to climb before you reach the top!";
		title = "Underling: Better than peon... but not much";
	}

	if(iPerc >= 71 && iPerc <= 80)
	{
		text = "Yay, you are a Hireling, still got's way's ta go, no power and very low wages... keep on working";
		title = "Hireling: You no longer suck (completely)";
	}

	if(iPerc >= 81 && iPerc <= 94)
	{
		text = "Okay, you are a peasant, which means \n that you serve a lord, not some stupid other peasant. \n You can also have an underling, or peon...";
		title = "Peasant: Woohoo!";
	}

	if(iPerc >= 95 && iPerc <= 100)
	{
		text ="You are a Greater Peasant, which is basically a peasant, \n only you get to have hirelings too";
		title ="Greater Peasant: :D";
	}

	if(iPerc >= 101 && iPerc <= 250)
	{
		text = "You are a Farmer, which means \n you get to choose the crops you grow, and \n you get paid for selling the crops. \n You can hire peasants and animals now!";
		title = "Farmer: Not bad";
	}

	if(iPerc >= 251 && iPerc <= 350)
	{
		text = "You are a greater Farmer, \n You can now hire greater peasants, and super animals";
		title = "Greater Farmer: ... sure";
	}

	if(iPerc >= 351 && iPerc <= 500)
	{
	    text = "You are a city urchin, \n nice, you are basically a homeless little theif. \n But you do have aquisition skills, can carry more money than Greater Farmers, \n and you live in the city. ";
        title = "City Urchin: Well, your in the city";
	}

	if(iPerc >= 501 && iPerc <= 750)
	{
	    text = "You have attained the lofty position of city hobo. \n You have the skill to use sit on your fat ass with \n a sign and people will give you gold. ";
	    title = "City Hobo: Personally, I would rather be an Urchin.";
	}

    if(iCode == 7777)
    {
    text = text + "\n You also happen to be the first mate of Commander Zark. Nice!";
    title = "First Mate & ";
    }

    Out("Alright, here are your statistics: \n \n \n");
    Out(title);
    Out("\n\n");
    Out(text);
    Out("\n\n\n");
    Out("\nWell, there are your results! Hope you are proud, but do try and score higher");
    pause();
    return true;


}


bool help()
{
    std::cout << "\\HELP: \n";
    std::cout << " 'help' - this is help \n";
    std::cout << " 'ranker' - launch the rank translator \n";
    std::cout << "\\ UPCOMING COMMANDS: \n";
    std::cout << " 'manage' - manage your items and equipment \n";
    std::cout << " 'peek' - connect to the internet to raise your %! \n";
    std::cout << "Thank your for using HELP\n";
    return pause();
}

bool pause()
{
std::cout << "\n Press c then enter to continue...";
char a;

        std::cin >> a;
        return true;
}


That's it. I know that items and creatures .h aren't problematic, but if you request I can post them no problem. Anyway, wouldn't it be nice if computers always worked the same? I have used std::cin to pause for a long time, and now... it just stops... I know that it's not good to pause this way (suspends the entire program or something like that) but I don't need super effiency right now. I just need it ta work! :) thanks. [edit] I know that I don't need to make those bool, but I though that it might fix it for some reason... didn't. Assume they are all void functions.

Share this post


Link to post
Share on other sites
That's a lot fo code to dump especially when one of your comments is "niether does returning from a function or something." For that problem we'll need more information or at the very least the smaller section of code that has this problem.

As for cin.get() not working, it's probably because there is input waiting to be processed. A quick way to get past this is to simply ignore the input with cin.ignore(). Your problem will probably go away if you put this before calling cin.get()

std::cin.ignore(1000); // Ignore up to 1000 characters on the input stream.

Share this post


Link to post
Share on other sites
Alright, well, this doesn't work:

void pause()
{
std::cout << "\n Press c then enter to continue...";
char a;
while(!(a == '\n'))
{
std::cin.ignore(10);
std::cin.get(a);
}
}





Yeah, that is problematic, doesn't crash or loop, but just skips,
cin.ignore doesn't work
and now for some reason, cin.get doesn't do anything. It just sits there. Doesn't take input or any of it. Do I need to inlcude a library to use that?
I figured out that the First call to std::cin.get() in my main function works fine. It is outside anyscope, save main.
I still have the loop issue, but I want the pause issue fixed first,
thanks!

Share this post


Link to post
Share on other sites

This topic is 4107 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this