Error message stating "Debug Assertion Failed". Can anyone help me find out why.

#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>

///////////////////////////////////////////////////////////////////////////////
// Namespaces used....
///////////////////////////////////////////////////////////////////////////////
using namespace std;

///////////////////////////////////////////////////////////////////////////////
// Type Definitions...
///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
// Function prototypes...
///////////////////////////////////////////////////////////////////////////////

int inputScore();
// prompt the user for the score and return it
int letter_grade();

string computeScore(int the_score);

void outputgrade(int score, string letter_grade);
// output the score and the corresponding percentage

///////////////////////////////////////////////////////////////////////////////
// Constants...
///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
//
// FUNCTION NAME: main
// PARAMETERS: None
// RETURN TYPE: int
// PURPOSE: Entry point for the application.
//
///////////////////////////////////////////////////////////////////////////////

int main()
{
int score = 0;
score = inputScore();

string grade = 0;
grade = computeScore ( score );
outputgrade( score, grade );


// exit the program with success (0 == success)
return 0;
}

///////////////////////////////////////////////////////////////////////////////
//
// FUNCTION NAME: inputScore
// PARAMETERS: None
// RETURN TYPE: int
// PURPOSE: Return the user-defined exam score.
//
///////////////////////////////////////////////////////////////////////////////

int inputScore()
{
int the_score = -1; // stores the user input value

// prompt the user...
cout << "Please enter the exam score: ";
// input the exam score...
cin >> the_score;

return the_score; // return the user input value
}

string computeScore(int the_score)
{
string grade;

if (the_score >= 86 && the_score <= 100)
{
grade = "A";
}
else if (the_score >= 71 && the_score <= 85)
{
grade = "C";
}
else if (the_score <= 70 && the_score>=0)
{
grade = "F";
}
return grade;
}

///////////////////////////////////////////////////////////////////////////////
//
// FUNCTION NAME: outputResults
// PARAMETERS: int score
// string letter_grade
// RETURN TYPE: void
// PURPOSE: Output the score and the corresponding percentage.
//
///////////////////////////////////////////////////////////////////////////////

void outputgrade(int the_score, string letter_grade)
{
// output the score and the letter grade with a descriptive message...
cout <<"The score you entered is "<< the_score << endl;
cout <<" Which results in a letter grade of "<< letter_grade << endl;
}
I think that the source of your problem is the statement

string grade = 0;

I think, that in this statement the constructor that uses const pointer to a character array is called and that pointer has value 0.

You can simply define

string grade;
or even

string grade = computeScore ( score );
Last edited on
string grade = "0";
or even better
string grade = computeScore ( score );
string grade = 0; grade is of type string, not int, do this: string grade("0");
Topic archived. No new replies allowed.