Thread: error code -1073741510 (0xc000013a) when running and nothing displays in cmd

  1. #1
    Registered User
    Join Date
    Feb 2015
    Posts
    5

    Post error code -1073741510 (0xc000013a) when running and nothing displays in cmd

    here is my code

    Assignment 2.cpp

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Your code is short enough to post in [code][/code] bbcode tags. One problem I see is that you need to be careful about the difference between = and ==
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Feb 2015
    Posts
    5

    thanks

    Quote Originally Posted by laserlight View Post
    Your code is short enough to post in [code][/code] bbcode tags. One problem I see is that you need to be careful about the difference between = and ==
    thank you, i would have posted with the code in the text feild but i thought that uploading the file would make it look nicer and that it would appear in the text area, first time posting on this site

  4. #4
    Registered User
    Join Date
    Feb 2015
    Posts
    5
    i was able to fix it so that it runs now (redid the entire code, removing the loop), but now the program is not randomly assigning the operand(sign/sgn/+-) for the operations, but it generates a random number for the number1 and number2 every startup.

    heres the code

    #include <iostream> //brings in librarys for certain functions
    #include <iomanip>
    #include <string>
    #include <stdlib.h>
    using namespace std;


    int main()
    {
    int number1;
    int number2;
    string sign;
    bool sgn;
    int answer;
    int correct;


    srand(time(NULL));
    number1 = rand() % 1000 + 1;
    number2 = rand() % 1000 + 1;
    sgn = rand() % 2;
    if (sgn = 0)
    sign = "+";
    else if (sgn = 1)
    sign = "-";
    else
    cout << "Error" << endl;
    std::cout.width(5); cout << std::right << number1 << endl;
    cout << sign << std::left << " " << number2 << endl;
    std::cout.width(5); cout << "_____" << endl;
    cout << "Please Type your Answer: " << endl;
    cin >> answer;
    if (sgn = 1)
    correct = number1 + number2;
    else
    correct = number1 - number2;
    if (answer == correct)
    cout << "You are Correct" << endl;
    else
    cout << "You are Incorrect" << endl;
    cout << "Have a Nice Day" << endl;
    std::cout << "Press ENTER to continue... " << flush; //this pauses the prompt window
    cin.ignore(cin.rdbuf()->in_avail() + 1);
    return 0;
    }
    Last edited by Chuck Charles; 02-06-2015 at 12:58 PM.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Put code in code tags.
    Code:
    #include <iostream> //brings in librarys for certain functions
    #include <iomanip>
    #include <string>
    #include <stdlib.h>
    using namespace std;
    
    
    int main()
    {
    	int number1;
    	int number2;
    	string sign;
    	bool sgn;
    	int answer;
    	int correct;
    
    
    	srand(time(NULL));
    	number1 = rand() % 1000 + 1;
    	number2 = rand() % 1000 + 1;
    	sgn = rand() % 2;
    	if (sgn = 0)
    		sign = "+";
    	else if (sgn = 1)
    		sign = "-";
    	else
    		cout << "Error" << endl;
    	std::cout.width(5); cout << std::right << number1 << endl;
    	cout << sign << std::left << " " << number2 << endl;
    	std::cout.width(5); cout << "_____" << endl;
    	cout << "Please Type your Answer: " << endl;
    	cin >> answer;
    	if (sgn = 1)
    		correct = number1 + number2;
    	else
    		correct = number1 - number2;
    	if (answer == correct)
    		cout << "You are Correct" << endl;
    	else
    		cout << "You are Incorrect" << endl;
    	cout << "Have a Nice Day" << endl;
    	std::cout << "Press ENTER to continue... " << flush; //this pauses the prompt window
    	cin.ignore(cin.rdbuf()->in_avail() + 1);
    	return 0;
    }
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    Feb 2015
    Posts
    5
    Found out why it never switched between + and -, i had it as a bool, and when you do the rand() % 2; it pulls a random integer not a T or F('1' or '0') and when it runs it gets stuck at 1.

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Chuck Charles
    i had it as a bool, and when you do the rand() % 2; it pulls a random integer not a T or F('1' or '0') and when it runs it gets stuck at 1.
    No, that is not the problem. Conversion from int to bool is well defined: zero is converted to false; non-zero is converted to true. The problem is what I noted in post #2: you need to be careful about the difference between = and ==. Look at:
    Code:
    sgn = rand() % 2;
    if (sgn = 0)
        sign = "+";
    else if (sgn = 1)
        sign = "-";
    else
        cout << "Error" << endl;
    • Suppose that rand() returns an even number. sgn would then be equal to 0. In the if statement, you then assign 0 to sgn. Since 0 evaluates to false, control proceeds to the else. If the if statement, you then assign 1 to sgn. Since 1 evaluates to true, you then assign "-" to sign.
    • Suppose that rand() returns an odd number. sgn would then be equal to 1. In the if statement, you then assign 0 to sgn. Since 0 evaluates to false, control proceeds to the else. If the if statement, you then assign 1 to sgn. Since 1 evaluates to true, you then assign "-" to sign.

    In other words, no matter what rand() returns, you always end up with "-" assigned to sign. Rather, you should use == to compare for equality, e.g.,
    [code]sgn = rand() % 2;
    Code:
    if (sgn == 0)
    {
        sign = "+";
    }
    else
    {
        sign = "-";
    }
    But this is a little dumb: sgn is a bool, so why compare it with 0? In fact, you do not need sgn at all:
    Code:
    if (rand() % 2 == 0)
    {
        sign = "+";
    }
    else
    {
        sign = "-";
    }
    I continue to use the braces here even though the block only contains one statement because I find that this makes a mistake when adding statements to a block less likely.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    Registered User
    Join Date
    Feb 2015
    Posts
    5

    Thanks

    Thank You

    Quote Originally Posted by laserlight View Post
    No, that is not the problem. Conversion from int to bool is well defined: zero is converted to false; non-zero is converted to true. The problem is what I noted in post #2: you need to be careful about the difference between = and ==. Look at:
    Code:
    sgn = rand() % 2;
    if (sgn = 0)
        sign = "+";
    else if (sgn = 1)
        sign = "-";
    else
        cout << "Error" << endl;
    • Suppose that rand() returns an even number. sgn would then be equal to 0. In the if statement, you then assign 0 to sgn. Since 0 evaluates to false, control proceeds to the else. If the if statement, you then assign 1 to sgn. Since 1 evaluates to true, you then assign "-" to sign.
    • Suppose that rand() returns an odd number. sgn would then be equal to 1. In the if statement, you then assign 0 to sgn. Since 0 evaluates to false, control proceeds to the else. If the if statement, you then assign 1 to sgn. Since 1 evaluates to true, you then assign "-" to sign.

    In other words, no matter what rand() returns, you always end up with "-" assigned to sign. Rather, you should use == to compare for equality, e.g.,
    [code]sgn = rand() % 2;
    Code:
    if (sgn == 0)
    {
        sign = "+";
    }
    else
    {
        sign = "-";
    }
    But this is a little dumb: sgn is a bool, so why compare it with 0? In fact, you do not need sgn at all:
    Code:
    if (rand() % 2 == 0)
    {
        sign = "+";
    }
    else
    {
        sign = "-";
    }
    I continue to use the braces here even though the block only contains one statement because I find that this makes a mistake when adding statements to a block less likely.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code now running but......
    By BenAber in forum C Programming
    Replies: 1
    Last Post: 04-27-2014, 08:42 AM
  2. Replies: 6
    Last Post: 08-09-2013, 11:52 AM
  3. Process Terminated with status -1073741510
    By Varethien in forum C Programming
    Replies: 5
    Last Post: 08-09-2011, 04:16 AM
  4. Running Exe in C++ Code.
    By Ti22 in forum C++ Programming
    Replies: 5
    Last Post: 03-23-2006, 01:29 PM
  5. running code EXACTLY once
    By Trauts in forum C++ Programming
    Replies: 12
    Last Post: 07-11-2003, 12:24 PM

Tags for this Thread