Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6247999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:58:37+00:00 2026-05-24T12:58:37+00:00

I have a kind of assertion error in this program, and unfortunately I’m quite

  • 0

I have a kind of assertion error in this program, and unfortunately I’m quite new to C++ and have no idea what this means:

#include "stdafx.h"
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime> // for time()
#include <windows.h> // for Sleep()

using namespace std;

string TakingInput()
{
    cout << "What do you want to say? ";
    string a;
    getline(cin, a);
    return a;
}

// Generate a random number between nLow and nHigh (inclusive)
unsigned int GetRandomNumber(int nLow, int nHigh)
{
    return (rand() % (nHigh - nLow + 1)) + nLow;
}
string jokeplease(string strInput)
{
    while (strInput.compare("jokeplease") == 0)
    {
        cout << endl;
        // This generates a randomnumber
        int nRandomNumber = GetRandomNumber(1, 10);

        // Every joke has a number which when stated true will show the specified joke
        if(nRandomNumber == 1)
        {
            cout << "Alle barna skrev dikt unntatt Ruben, for han kunne ikke rime." << endl;
        }
        else if(nRandomNumber == 2)
        {
            cout << "Gubben va på kafe og overhørte følgende fra et forelsket par: ”Olga æ e så\n" <<
                    "forelska i dæ at når æ ser på dæ så klar æ næsten ikke å ta te mæ føde.” Gubben\n" <<
                    "syns at det dær va fine ord som han skulle overføre på kjærringa når han kom\n" <<
                    "hjem. Da dæm satt i kjøkkenkroken å kosa sæ med en kopp kaffe, så utbrøut han:\n" <<
                    "”Marta, når æ ser på dæ, så mest æ reint matløsta!”" << endl;
        }
        else if(nRandomNumber == 3)
        {
            cout << "Alle barna så inn i komfyren untatt Knut han så ut." << endl;
        }
        else if(nRandomNumber == 4)
        {
            cout << "En blondine kjører bak en lastebil og gir signal til sjåføren om å stoppe,\n" << 
                    "sjåføren stopper og blondine sier \"du mister lasten din\", sjåføren bare kjører\n" <<
                    "vidre. etter litt gir blondine signal om at han skal stoppe igenn og hun sier\n" << 
                    "\"du mister lasta di!\" sjåføren bryr seg ikke og kjører vidre. etter litt gir\n" << 
                    "blondine signal om at sjåføren skal stoppe og sjåføren sier \"du, det er midt på\n" << 
                    "vinteren, og jeg er ute og strør\"" << endl;
        }
        else if(nRandomNumber == 5)
        {
            cout << "Alle barna gjorde fra seg i potta utenom Hanne, hun gjorde det i spannet." << endl;
        }
        else if(nRandomNumber == 6)
        {
            cout << "Noen plasser sjekker legen hva barnet kommer til å bli ved å stikke hånden\n" <<
                    "sin opp i ræven på ungen. Hvis det skriker blir det en sanger, hvis det sparker\n" <<
                    "vil det bli en fotballspiller og hvis det smiler blir den en homse." << endl;
        }
        else if(nRandomNumber == 7)
        {
            cout << "Norsken, dansken og svensken skulle bade i et badebaseng. Når de kom til\n" << 
                    "badebasenget sa en dame: Det basenget er magisk. Du får et ønske. Da de kom\n" <<
                    "bort til bassenget sa norsken: Jeg ønsker meg masse sjokolade. Så ble bassenget\n" << 
                    "helt fullt med masse sjokolade. Så spiste han det opp. Så sa dansken: jeg ønsker\n" << 
                    "meg masse bananer. Så var det masse bananer i bassenget. Så gikk svensken bort\n" << 
                    "til bassenget, og så sklei han på bananskallet til dansken. Så sa han skitt og\n" << 
                    "da ble bassenget helt fullt med dritt." << endl;
        }
        else if(nRandomNumber == 8)
        {
            cout << "Tre gutter ble sendt til rektor.\n" <<
                    "\"Hva har dere gjort for noe galt da?\" spurte rektor.\n" <<
                    "\"Jeg har kastet stein i vannet\", svarte den ene.\n" <<
                    "…" <<
                    "\"Tja, det er vel ikke så farlig\", sa rektor.\n" <<
                    "\"Men hva har du gjort da?\" sa han til den andre.\n" <<
                    "\"Jeg har også kastet stein i vannet.\"\n" <<
                    "\"Det er vel ikke så farlig. Hva har du gjort da?\" sa han til den tredje.\n" <<
                    "\"Det er jeg som er Stein…\"" << endl;
        }
        else if(nRandomNumber == 9)
        {
            cout << "En brunette og en blondine hopper ut fra et fly. Hvem lander først, og hvorfor?\n" <<
                    "Brunetta lander først, fordi blondina stopper 5 ganger for å spørre om veien." << endl;
        }
        else if(nRandomNumber == 10)
        {
            cout << "Martin: - Gaute er god til å kaste ball.\n" <<
                    "Mor: - Jasså?\n" <<
                    "Martin: - Ja, han traff lillebroren sin i hodet fra 5 meter!" << endl;
        }
        else
        {
            cout << "Error: Unexpected result when retrieving randomnumber!" << endl;
        }
        cout << endl;
        return 0;
    }
    return 0;
}
void OtherStatements(string strInput)
{
    if(strInput.compare("what") == 0||strInput.compare("what?") == 0||strInput.compare("WHAT?") == 0)
    {
        cout << "WHAT?? WHAAAAAAAAAAAAAAT? WHHHAEEEHT? WHAEET WHAET ...";
        Sleep(3000);
        cout << "what?" << endl;
    }
}
string ExitTime(string strInput)
{
    while (strInput.compare("bedtime") == 0||strInput.compare("leave") == 0)
    {
        cout << "Do you want to leave? ";
        string strExitLine;
        getline(cin, strExitLine);
        if (strExitLine.compare("yes") == 0||strExitLine.compare("YES") == 0)
        {
            cout << endl;
            cout << "Whatever! I'm bored!" << endl; 
            cout << "See you later!" << endl;
            exit(1);
        }   
        else if (strExitLine.compare("no") == 0||strExitLine.compare("NO") == 0)
        {
            cout << endl;
            cout << "Well stop whining then!" << endl;
            break;
        }
        else
        {
            cout << endl;
            cout << "I'm a bloddy computer! Speak computer-friendly!" << endl;
        }
    }
    return 0;
}

int main()
{
    cout << "JokePlease v0.01\n" << endl;


        // Taking an input from the user
        string strInput = TakingInput();

        // This prints a random joke when jokeplease is entered
        jokeplease(strInput);

        // Other statements than jokeplease goes here
        OtherStatements(strInput);

        // Here you come when it's time to leave!
        ExitTime(strInput); 

    return 0;
}

I can compile my program without getting any errors, but at once i write something into the console-cin (found inside the TakingInput function), it crashes, and prints an error.

The expression printed in the error message says Expression: invalid null pointer, and something about … c:\program ... include\xtring line: 930.

Please help me little newbie.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:58:38+00:00Added an answer on May 24, 2026 at 12:58 pm

    You are returning a zero-value (i.e., an integer) in a function that should be returning a std::string object with both your jokeplease and ExitTime functions. Since both functions are passing back a temporary string object, the compiler has to initialize the object from some value (or use a default-constructor). In your current scenario, you are trying to initialize it with basically a pointer to NULL rather than a pointer to a valid string literal (i.e., std::string is being called with the constructor that takes a const char* argument, and you’re passing it a NULL-pointer).

    When looking at both functions, it actually doesn’t appear as though they should be returning anything, i.e., you should be making both of them void.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need help have no idea the thought process in doing this kind of simplification.
I have this kind of node in my xml document: <parent ...> <a .../>
I have this kind of code below, how can I bind the visibility of
I have this kind of setup : Overridden BaseRunserverCommand that adds another option (--token)
I have this kind of table, it has many rows and each row has
I have kind of a complicated case and am wondering how this would work
I have this kind of table on my Database MySql : CREATE TABLE `users`
have such kind of error. When adding Redirect 301 rule to .htaccess file like:
I have kind of library which uses a bunch of its own perf counters.
I have some kind of problem with jQuery selectors. Let's say i want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.