[RESOLVED] Need help figuring out why I long random negative number in output
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Thread: [RESOLVED] Need help figuring out why I long random negative number in output

  1. #1
    Join Date
    Mar 2017
    Posts
    3

    [RESOLVED] Need help figuring out why I long random negative number in output

    Hi I am new here I am have some trouble with my program. I can seem to figure out why I am getting this long random negative number when I am trying to get the total possible points based on the point value of the question in the file. Which I got to work in my displayQuizQuestions function in the Quiz class. But now I cant get it to work in my student class. I keep trying different stuff but nothing is working. Could anyone take a look at my code and give me some advice on what I'm doing wrong? Here is what I have right now, sorry for the mess I am changing stuff over and over and trying different things to get it to work.

    Code:
    #include <iostream>
    #include <string>
    #include <fstream>
    #include <cstdlib>
    #include <limits>
    int score;
    class questions//base class
    {
    protected://using protected rather than private for inheritance to subclasses 
    	std::string question;
    	std::string answer;
    	int value;
    	std::string questionType;
    
    public:
    	questions::questions()
    	{
    
    	}
    	virtual questions::~questions()
    	{
    
    	}
    
    	std::string getQuestion()//gets the question
    	{
    		return question;
    	}
    
    	virtual int getValue() //gets the point value of the question
    	{
    		return value;
    	}
    
    	virtual std::string getQuestionType()// gets the type of question
    	{
    		return questionType;
    	}
    
    
    	virtual void setQuestion(std::string answer, int value)
    	{
    	}
    	virtual void setNewQuestion(std::string answer, int value)
    	{
    	}
    	virtual void printOptions()
    	{
    	}
    
    	virtual std::string getAnswer()
    	{
    		return answer;
    	}
    };
    
    
    class tfQuestion : public questions// subclass of questions class for true and false questions
    {
    private:
    	std::string options;
    	std::string a1;
    public:
    	tfQuestion::tfQuestion()
    	{
    
    	}
    	tfQuestion::~tfQuestion()
    	{
    
    	}
    	void setQuestion(std::string theQuestion, int pointValue)
    	{
    		std::string theAnswer;
    		questionType = "TF";
    		question = theQuestion;
    		value = pointValue;
    		options = "true/false";
    		//get the answer from the file
    		std::getline(std::cin, theAnswer);
    		answer = theAnswer;
    	}
    
    	/*void setNewQuestion(std::string theQuestion, int pointValue)
    	{
    	std::string theAnswer;
    	questionType = "TF";
    	question = theQuestion;
    	value = pointValue;
    	options = "true/false";
    	//get the answer from user
    	std::cout << "Enter answer true/false\n";
    	std::getline(std::cin, theAnswer);
    	answer = theAnswer;
    	}*/
    
    	int getValue() //gets the point value of the question
    	{
    		return value;
    	}
    
    	std::string getQuestionType()// gets the type of question
    	{
    		return questionType;
    	}
    
    	std::string getQuestion()
    	{
    		return question;
    	}
    
    	void printOptions()//prints the options for that question
    	{
    		std::cout << question << std::endl;
    
    		//std::cout << answer << std::endl;//this stops output of answer for TF
    	}
    
    	std::string getAnswer()//outputs the answer for that question
    	{
    		return answer;
    	}
    };
    
    
    
    class mcQuestion : public questions//subclass of questions class for multiple choice questions
    {
    private:
    	int numberOfOptions;
    	std::string mcAnswers[6];
    public:
    	mcQuestion::mcQuestion()
    	{
    
    	}
    	mcQuestion::~mcQuestion()
    	{
    
    	}
    	void setQuestion(std::string theQuestion, int pointValue)
    	{
    		std::string line;
    		questionType = "MC";
    		std::getline(std::cin, line);
    		numberOfOptions = atoi(line.c_str());
    		question = theQuestion;
    		value = pointValue;
    		//get the individual choice lines and load to options array
    		for (int count = 0; count < numberOfOptions; count++)
    		{
    			std::getline(std::cin, line);
    			mcAnswers[count] = line;
    		}
    		//get the answer from the file and load into answer
    		std::getline(std::cin, line);
    		answer = line;
    	}
    
    	/*	void setNewQuestion(std::string theQuestion, int pointValue)
    	{
    
    	std::string line;
    	questionType = "MC";
    	//get the number of choices from the user
    	/*std::cout << "Enter the number of choices:  ";
    	std::getline(std::cin, line);
    	numberOfOptions = atoi(line.c_str());
    
    	question = theQuestion;
    	value = pointValue;
    	//get the individual choice lines and load to options array
    	for (int count = 0; count < numberOfOptions; count++)
    	{
    	std::cout << "\nEnter next option:  ";
    	std::getline(std::cin, line);
    	mcAnswers[count] = line;
    	}
    	//get the answer from the user and load into answer
    	std::cout << "\nEnter Answer:  ";
    	std::getline(std::cin, line);
    	answer = line;
    	}	*/
    
    	void printOptions()// prints the questions, options, and answer
    	{
    		char first = 'A';
    		std::cout << question << std::endl;
    		for (int count = 0; count < numberOfOptions; count++)
    		{
    			std::cout << "(" << first++ << "): " << mcAnswers[count] << "\n";
    		}
    		//std::cout << answer << "\n";//This stops output of answer on MC
    	}
    
    	int getValue() //gets the point value of the question
    	{
    		return value;
    	}
    
    	std::string getQuestionType()// gets the type of question
    	{
    		return questionType;
    	}
    
    	std::string getAnswer()// prints the answer
    	{
    		return answer;
    	}
    };
    
    class Quiz : public questions
    {
    private:
    	std::string fileName;
    	//questions *myQuestions[10];
    	//int numberOfQuestions;
    	std::string theAnswer;
    	std::string qtype;
    	std::string theAnswerIs;
    	std::string ans[6];
    protected:
    	
    	questions *myQuestions[6];
    	int numberOfQuestions;
    	int pointValue[6];
    	int totalPossiblePoints = 0;
    
    public:
    	Quiz::Quiz()
    	{
    
    	}
    	Quiz::~Quiz()
    	{
    
    	}
    	void setloadQuiz(int num)
    	{
    		std::ifstream infile;
    		infile.clear();
    		//checking to see if user specified file exist, as well as making sure the user has used the correct format
    		while (!infile.is_open())
    		{
    			std::cout << "Please enter the .txt file name: " << std::endl;
    			std::getline(std::cin, fileName);
    			//fileName += ".txt";
    			infile.open(fileName.c_str(), std::ios::in | std::ios::binary);
    			if (infile)
    				break;
    			std::cout << "Either the file doesn't exist or you forgot the .txt extension. ";
    			std::cout << "Please try again. " << std::endl << std::endl;//promt user to try again if the file name is invalid
    		}
    
    
    		//std::ifstream infile("quiz.txt");
    		std::streambuf *cinbuf = std::cin.rdbuf();       //save old buf
    		std::cin.rdbuf(infile.rdbuf());             //redirect std::cin to infile.txt!
    
    		std::string line;
    		std::string theQuestion;
    		std::string questiontype;
    		//std::string theAnswer;
    		int  questionvalue;
    
    		while (true)//error check to ensure the file has an acceptable amount of questions
    		{
    
    			//get the number of questions from the first line in the file
    			//std::getline(infile, line);
    			std::getline(std::cin, line);
    			numberOfQuestions = atoi(line.c_str());
    			if (numberOfQuestions != 6)
    			{
    				std::cout << "Error! The quiz has too many or too litte questions. The desired amount is \'6\'" << std::endl;
    				std::cout << "Please check the file to ensure there is an acceptable amount of questions." << std::endl;
    				throw;
    			}
    			else
    			{
    				break;
    			}
    		}
    		for (int count = 0; count < numberOfQuestions; count++)
    		{
    			//std::getline(infile, line);
    			std::getline(std::cin, line);
    			//get the next line with the question type and the value of the question
    			int npos = line.size();
    			int prev_pos = 0;
    			int pos = 0;
    			while (line[pos] != ' ')
    				pos++;
    			questiontype = line.substr(prev_pos, pos - prev_pos);
    			prev_pos = ++pos;
    			questionvalue = atoi(line.substr(prev_pos, npos - prev_pos).c_str()); // Last word
    
    			if (questiontype == "TF")//do this if questiontype = TF
    			{
    				myQuestions[count] = new tfQuestion;
    				//std::getline(infile, line);
    				std::getline(std::cin, theQuestion);
    				myQuestions[count]->setQuestion(theQuestion, questionvalue);
    			}
    
    			if (questiontype == "MC")//do this if questiontype = MC
    			{
    				myQuestions[count] = new mcQuestion;
    				//std::getline(infile, line);
    				std::getline(std::cin, theQuestion);
    				myQuestions[count]->setQuestion(theQuestion, questionvalue);
    			}
    
    		}
    		std::cin.rdbuf(cinbuf);//restore cin to standard input
    		infile.close();//close the file stream
    		//return numberOfQuestions;
    	}
    
    	int getloadQuiz()
    	{
    		return numberOfQuestions;
    	}
    
    	void setdisplayQuizQuestions(int num)
    	{
    		score = 0;
    		//print out the questions that have been processed
    		for (int i = 0; i < num; i++)
    		{
    			qtype = myQuestions[i]->getQuestionType();
    			std::cout << qtype << " " << myQuestions[i]->getValue() << "\n";
    			myQuestions[i]->printOptions();
    			theAnswerIs = myQuestions[i]->getAnswer();
    			std::cout << theAnswerIs << std::endl;
    			std::cout << "\n";
    			std::cout << "Please enter your answer: ";
    			std::cin >> ans[i];
    			std::cout << ans[i].size() << "\n" << theAnswerIs.size() << std::endl;
    
    			if (!theAnswerIs.empty() && theAnswerIs[theAnswerIs.size() - 1] == '\r')
    				theAnswerIs.erase(theAnswerIs.size() - 1);
    			std::cout << ans[i].size() << "\n" << theAnswerIs.size() << std::endl;
    			if (theAnswerIs == ans[i])
    			{
    				std::cout << "You are correct, the answer is: " << theAnswerIs << '\n';
    				score++;
    				std::cout << "Your current score is " << score << std::endl;
    			}
    			else
    			{
    				std::cout << "Incorrect, the correct answer is: " << theAnswerIs << std::endl;
    				std::cout << "Your score is " << score << std::endl;
    			}
    		}
    	}
    		int getdisplayQuizQuestions()
    		{
    			return 0;
    		}
    		/*		for (int i = 0; i < numquestions; i++)
    				{
    					pointValue[i] = myQuestions[i]->getValue();
    				}
    				for (int i = 0; i < 6; i++)
    				{
    					std::cout << "the point value of each question is " << pointValue[i] << std::endl;
    					totalPossiblePoints += pointValue[i];
    					std::cout << "The total possible points are: " << totalPossiblePoints << std::endl;
    
    				}
    				std::cout << totalPossiblePoints << std::endl;
    				//delete myQuestions[10];
    			}
    */
    //Above works if uncommented to display the total points possible based on what the question value is in the file 
    //but I cant get it to work when trying to implement in the student class...
    
    	int  getPointValue()
    	{
    			for (int i = 0; i < numberOfQuestions; i++)
    				{
    					pointValue[i] = myQuestions[i]->getValue();
    				}
    				for (int i = 0; i < 6; i++)
    				{
    					std::cout << "the point value of each question is " << pointValue[i] << std::endl;
    					totalPossiblePoints += pointValue[i];
    					std::cout << "The total possible points are: " << totalPossiblePoints << std::endl;
    				}
    				
    				std::cout << totalPossiblePoints << std::endl;
    		return totalPossiblePoints;
    	}
    	void setPointValue(int num)
    	{
    		for (int i = 0; i < numberOfQuestions; i++)
    				{
    					pointValue[i] = myQuestions[i]->getValue();
    				}
    				for (int i = 0; i < 6; i++)
    				{
    					std::cout << "the point value of each question is " << pointValue[i] << std::endl;
    					totalPossiblePoints += pointValue[i];
    					std::cout << "The total possible points are: " << totalPossiblePoints << std::endl;
    				}
    				
    				std::cout << totalPossiblePoints << std::endl;
    	}
    	
    	
    };
    class Student
    {
    private:
    	int pointsPossible;
    	int pointsScored = 0;
    	std::string name;
    	int yourScore = 0;
    
    	//int totalScore;
    public:
    	Student::Student()
    	{
    
    	}
    	Student::~Student()
    	{
    
    	}
    	
    /*	void student()
    	{
    		std::cout << "Please enter your name" << std::endl;
    		std::getline(std::cin, name);
    		std::cout << "Hello " << name << std::endl
    			<< "The total possible points are: " << pointsPossible << std::endl
    			<< "You scored " << score << " points out of " << pointsPossible << " possible points." << std::endl;
    }
    */
    	int getPointsPossible()
    	{
    		return pointsPossible;
    	}
    	void setPointsPossible(int num)
    	{
    		Quiz obj;
    		num = 0;
    		obj.setPointValue(num);
    		num = obj.getPointValue();
    		//student();
    	}
    
    };
    
    /*pointsPossible = getPointValue();
    		std::cout << "Please enter your name" << std::endl;
    		std::getline(std::cin, name);
    		std::cout << "Hello " << name << std::endl
    			<< "The total possible points are: " << pointsPossible << std::endl
    			<< "You scored " << score << " points out of " << pointsPossible << " possible points." << std::endl;
    
    	}
    	int Score()
    	{
    		yourScore = score;
    		return yourScore;
    	}
    	int getPointValue()
    	{
    		for (int i = 0; i < n; i++)
    		{
    			Quiz::pointValue[i] = Quiz::myQuestions[i]->getValue();
    		}
    		for (int i = 0; i < 6; i++)
    		{
    			std::cout << "the point value of each question is " << pointValue[i] << std::endl;
    			totalPossiblePoints += pointValue[i];
    			std::cout << "The total possible points are: " << totalPossiblePoints << std::endl;
    
    		}
    		std::cout << totalPossiblePoints << std::endl;
    		return totalPossiblePoints;
    */
    
    
    int menu()
    {
    	int selection = 0;
    
    
    	std::cout << "Please select an option from the list below." << std::endl;
    	//display the menu
    	std::cout << "Menu";
    	std::cout << "======" << std::endl;
    	std::cout << "1 - Load quiz." << std::endl;
    	std::cout << "2 - Take quiz." << std::endl;
    	std::cout << "3 - Show quiz results." << std::endl;
    	std::cout << "4 - Press 4 to exit." << std::endl << std::endl;
    	std::cout << "Enter selection: ";
    	// read user selection
    	while (true)//while loop to ensure user selects an option on the menu
    	{
    		std::cin >> selection;
    		if (std::cin.fail())//if() to make sure an endless loop doesn't happen if a char is entered.
    		{
    			std::cerr << "Please enter an integer number." << std::endl;
    			std::cin.clear();
    			std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
    		}
    		if (selection == 1 || selection == 2 || selection == 3 || selection == 4)//if() to make sure only the options on the menu are avaible to select 
    		{
    			break;
    		}
    		std::cout << "The options are: \'1\'\'2\'\'3\' or \'4\': ";
    	}
    	std::cin.ignore();
    	return selection;
    }
    
    
    
    int main()
    {
    
    	Student Sobj;
    	Quiz obj;
    	int num = 0;
    
    	int selection = 0;
    	//std::string quizName = "quiz.txt";
    
    	while ((selection = menu()) != 4)
    		switch (selection)
    		{
    		case 1:
    			std::cout << "You selected - Load quiz." << std::endl;
    			obj.setloadQuiz(num);
    			num = obj.getloadQuiz();
    			break;
    
    		case 2:
    			std::cout << "You selected - Take quiz." << std::endl << std::endl;
    			std::cout << "========== Quiz: ==========" << std::endl;
    			obj.setdisplayQuizQuestions(num);
    			num = obj.getdisplayQuizQuestions();
    			break;
    
    		case 3:
    			std::cout << "You selected - Show quiz results." << std::endl;
    			//need to call a function that displays the results after taking the quiz
    			Sobj.setPointsPossible(num);
    			num = Sobj.getPointsPossible();
    			
    			break;
    
    		case 4:
    			break;
    
    			//if  1, 2, or 3 is not selected then go to the default case
    		default: std::cout << "Invalid selection. Please try again.\n";
    			// no break in the default case
    		}
    	std::cout << std::endl << std::endl;
    	std::cout << "Thank you for using this program. Goodbye.";
    	std::cin.get();
    	return 0;
    }

    On this line pointValue[i] = myQuestions[i]->getValue(); the myQuestions[i] array says myQuestions is undefined on the watch list in the debugger. Also sometimes after I try something different it says:
    Code:
    myQuestions[i]->getValue a pointer to a bound function may only be used to call the function
    the output on the console for both errors are the same the long random negative numbers. Which I am guessing is why I am getting these random negative number instead of whats in the file. I keep trying to figure out how to fix it but nothing seems to work. The only way I can get it to work is if I take the code in the new int setPointValue() function, eliminate the two new functions I have at the end of the quiz class and put the code inside of the void displayQuizQuestions(int numquestions). I think I understand why it works there and not in the new function. Because myQuestions[i] is no longer in scope since it left the function and moved to a different one. I can't figure out how to retrieve the data that I need from outside the scope of that function.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    19,006

    Re: Need help figuring out why I long random negative number in output

    Quote Originally Posted by Humbleone View Post
    On this line pointValue[i] = myQuestions[i]->getValue(); the myQuestions[i] array says myQuestions is undefined on the watch list in the debugger. Also sometimes after I try something different it says:
    Code:
    myQuestions[i]->getValue a pointer to a bound function may only be used to call the function
    the output on the console for both errors are the same the long random negative numbers.
    What is the value of index [i] in case of the error message(s)?
    Is it within the array bounds?
    And were all the array elements already initialized?
    Victor Nijegorodov

  3. #3
    Join Date
    Mar 2017
    Posts
    3

    Re: Need help figuring out why I long random negative number in output

    not sure what you mean by "What is the value of index [i] in case of the error message(s)?"... It is not necessarily an error. I am using the debugger in visual studio and in the watch list it says the myQuestions[i] array says myQuestions is undefined. If your asking what the values that are printed to the console they are this:
    Menu======
    1 - Load quiz.
    2 - Take quiz.
    3 - Show quiz results.
    4 - Press 4 to exit.

    Enter selection: 3
    You selected - Show quiz results.
    the point value of each question is -858993460
    The total possible points are: -8.58993e+08
    the point value of each question is -858993460
    The total possible points are: -1.71799e+09
    the point value of each question is -858993460
    The total possible points are: -2.57698e+09
    the point value of each question is -858993460
    The total possible points are: -3.43597e+09
    the point value of each question is -858993460
    The total possible points are: -4.29497e+09
    the point value of each question is -858993460
    The total possible points are: -5.15396e+09
    -5.15396e+09
    The values that I am retrieving from the file should all be 1 then they should be add for a total value at the end. So it should look like this
    the point value of each question is 1
    The total possible points are: 1
    the point value of each question is 1
    The total possible points are: 2
    the point value of each question is 1
    The total possible points are: 3
    the point value of each question is 1
    The total possible points are: 4
    the point value of each question is 1
    The total possible points are: 5
    the point value of each question is 1
    The total possible points are: 6
    my code works if i use it inside of the setdisplayQuizFunction but when trying to implement outside of that function it gives me the random negative number.

    It is within the array bounds. I think because the array is out of scope it's not working but I can't figure out a way to solve the problem.

    All the array elements were not initialized but I will try that now to make sure that is not the problem.

    Thanks for the reply
    Humbleone

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    19,006

    Re: Need help figuring out why I long random negative number in output

    Quote Originally Posted by Humbleone View Post
    not sure what you mean by "What is the value of index [i] in case of the error message(s)?"... It is not necessarily an error. I am using the debugger in visual studio and in the watch list it says the myQuestions[i] array says myQuestions is undefined. If your asking what the values that are printed to the console they are this:
    Code:
    the point value of each question is -858993460
    The total possible points are: -8.58993e+08
    the point value of each question is -858993460
    The total possible points are: -1.71799e+09
    the point value of each question is -858993460
    ...
    Well, the value -858993460 is in hex 0xCCCCCCCC. This value is used by Microsoft's C++ debugging runtime library to mark uninitialized stack memory. See http://www.asawicki.info/news_1292_m..._visual_c.html

    Now you have to analize and debug your code more deeper to find out why this memory was not initialized!
    Victor Nijegorodov

  5. #5
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,872

    Re: Need help figuring out why I long random negative number in output

    Code:
    void setPointsPossible(int num)
    	{
    		Quiz obj;
    		num = 0;
    		obj.setPointValue(num);
    		num = obj.getPointValue();
    		//student();
    	}
    This doesn't seem correct as variable obj only exists during the function. It is destroyed when the function exits. Shouldn't obj be a Student class variable - and then you won't need the variable obj in main()? I've created a simple test quiz file and made this change to the code and I'm showing expected results after doing option 1 and then option 3.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.5.0)

  6. #6
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,872

    Re: Need help figuring out why I long random negative number in output

    Some of this code can be simplified. eg
    Code:
    numberOfQuestions = atoi(line.c_str());
    becomes
    Code:
    numberOfQuestions = stoi(line);
    see http://www.cplusplus.com/reference/string/

    But it is also easier if this type of data is read via stream extraction. Consider
    Code:
    std::getline(std::cin, line);
    numberOfQuestions = atoi(line.c_str());
    as
    Code:
    cin >> numberofQuestions;
    Also consider
    Code:
    		for (int count = 0; count < numberOfQuestions; ++count)
    		{
    			int questionvalue;
    			std::string questiontype;
    			std::string theQuestion;
    
    			cin >> questiontype >> questionvalue;
    			if (questiontype == "TF")
    				myQuestions[count] = new tfQuestion;
    			else
    				if (questiontype == "MC")
    					myQuestions[count] = new mcQuestion;
    				else {
    					cout << "Bad question type " << questiontype << endl;
    					break;
    				}
    
    			cin.ignore(100, '\n');
    			std::getline(std::cin, theQuestion);
    			myQuestions[count]->setQuestion(theQuestion, questionvalue);
    		}
    Note that the .ignore() is required before the getline() as stream extraction doesn't remove the trailing \n. Without it getline() obtains a blank line of just the \n.

    PS Also note that dynamic memory has been allocated with new but has not been released anywhere with delete.
    Last edited by 2kaud; March 23rd, 2017 at 02:11 PM. Reason: PS
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.5.0)

  7. #7
    Join Date
    Mar 2017
    Posts
    3

    Re: Need help figuring out why I long random negative number in output

    @2kaud, I want to thank you for all you help. Thanks to your suggestions I got my program completely working as it should. I can't thank you enough, I have been stuck on this for days now. I am still very new to programming, but I am loving the challenges it brings and trying to solve them. Thanks again!!!!

  8. #8
    Join Date
    Sep 2017
    Posts
    2

    Re: Need help figuring out why I long random negative number in output

    Could I take a look at your final code, please?

  9. #9
    Join Date
    Sep 2017
    Posts
    2

    Re: Need help figuring out why I long random negative number in output

    @2kaud Would you mind showing me this change in the code you had? I'm not able to figure it out, thanks a lot!

  10. #10
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,872

    Re: Need help figuring out why I long random negative number in output

    Quote Originally Posted by rooney.theman View Post
    @2kaud Would you mind showing me this change in the code you had? I'm not able to figure it out, thanks a lot!
    What's your current code and what is the problem you're having?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.5.0)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


On-Demand Webinars (sponsored)