locked
Cant debug current version of code. Assignment due soon. RRS feed

  • Question

  • Hi, Im trying to debug a version of my code after making substantial edits and i cannot seem to get it to use the updated version. I have tried repairing through the installer, i have tried uninstalling visual studio and a few other things on google. No matter what it uses the same version of my code. I even made a new project and did a simple hello world and it still used the same version of my old code. I have an assignment due by midnight tonight. I'm fairly new to visual studio and coding in general. Some of the stuff I found on google, I do not understand. Please help!

    I'm coding in C++

    Using Visual Studio Enterprise 2019

    edit. Ive tried rebuilding, cleaning, enabling edit and continue


    • Edited by IIEleven11 Sunday, August 16, 2020 10:41 PM
    Sunday, August 16, 2020 10:28 PM

All replies

  • Here is a copy of my code along with a shot of the output window. My code  used to be a switch statement but now i'm using if and do while loop. So I no longer have the option to press # for "...". Its type "degrees' for example. I understand there may be some error in the code, I cant debug it to fix them, it shows me no errors. I dont think the problem lies in my code though. Its something else I did to trigger this. 
    #include <iostream>
    #include <iomanip>
    #include <string>
    using namespace std;

    void myFunction();

    string userAnswer;
    double userDegrees;
    double userDist = 1;
    long userSpeed;
    double tempConversion;
    double degConversion;
    double spConversion;
    double inches = 1;
    double feet = 1;

    int main()
    {
    cout << "\nHello Welcome to the Number Converter.\n" << endl;
    cout << "I can convert either celsius to farenheight, centimeters to inches/feet, and kilometers per hour to miles per hour.\n" << endl;
    cout << "Please designate which conversion you would like to do by typing:\n Number. \"1\" for degrees. \n Number. \"2\" for distance.\n Number, \"3\" for speed. \n Or you can type Number 9 to exit. \n" << endl;
    cin >> userAnswer;
    return 0;
    }
    void myFunction()
    {
    if (userAnswer == "degrees" || userAnswer == "Degrees")
    {
    cout << "You pushed \"Degrees\", thank you. Please enter the number youd like to convert in Farenheight: " << endl;
    cin >> userDegrees;
    degConversion = userDegrees * 1.8 + 32;
    cout << userDegrees << " degrees celsius" << " is " << degConversion << " degrees ferenheight." << endl;
    }
    else if (userAnswer == "distance" || userAnswer == "Distance")
    {
    cout << "You chose \"Distance\", thank you. Please enter the numbers you would like to convert: " << endl;
    cin >> userDist;
    feet = (userDist / 30.48);
    inches = userDist * (1 / 2.54);
    cout << userDist << " is " << feet << " or " << inches << " inches." << endl;
    }
    else if (userAnswer == "speed" || userAnswer == "Speed")
    {
    cout << "You chose \"Speed\", thank you.Please enter the numbers you would like to convert: " << endl;
    cin >> userSpeed;
    spConversion = userSpeed * 0.6213711922;
    cout << userSpeed << " mph is: " << spConversion << " kph." << endl;
    }
    else
    {
    cout << "sorry please enter another number or type quit to exit" << endl;
    }
    }

    Edit. I tried posting a screenshot but cant because my account isnt verified. I thought i verified it but i still cant
    • Edited by IIEleven11 Sunday, August 16, 2020 10:52 PM
    Sunday, August 16, 2020 10:44 PM
  • Since you cannot post a screen shot, you need to tell us what happens when you try to debug it.

    One immediate problem is main never calls myFunction.  As soon as the user enters the value you request, your program exits.

    Once you fix that problem, you should look at the message which requests the user to enter a number and compare that with the values that actually myFunction tests for.

    Problems with designing and coding programs are better dealt with in the C++ forums:
         https://social.msdn.microsoft.com/Forums/en-US/home?forum=vclanguage&filter=alllanguages
         https://social.msdn.microsoft.com/Forums/en-US/home?forum=vcgeneral&filter=alllanguages

    Sunday, August 16, 2020 11:44 PM
  • No matter what changes I make to the code it does not get represented in the output window. So i know it ss not an issue with the code. I can literally write anything I want, save it debug it and the same old code will output. I even made a brand new file  in a new save and did a hello world and it reused the old code/switch statement with no hello world in sight.
    Sunday, August 16, 2020 11:48 PM
  • If this was a coding issue I wouldn't be here asking for help with visual studio. I did state all of this in my first post. Please be more thorough.  I apologize If I sound like i'm on edge, its because I am. I have a very large assignment due in six hours and i cannot work on it. Its been like this for over 7 hours of me trying to fix this. I haven't slept, now if you know what could be the issue, after reading what I had to say in my original two posts, please let me know. Please note the things I have tried. If you would like me to retry any of them Id be more then happy too. Thanks.
    Sunday, August 16, 2020 11:52 PM
  • If someone from microsoft can verify me so I can post screenshots please do. I have gone through the proper channels on the  website and it says i'm verified. But i still do not have permission. Until then i'll upload the images to a third party sight and get them linked through a typed web address now.
    Sunday, August 16, 2020 11:55 PM

  • add an h before "ttps" and they should work

    ttps://i.imgur.com/1P28Hsl.png

    ttps://i.imgur.com/wklyI4N.png

    ttps://i.imgur.com/CxJB30i.png



    • Edited by IIEleven11 Monday, August 17, 2020 12:04 AM
    Monday, August 17, 2020 12:03 AM
  • It's not what you don't know that hurts, it's what you know that ain't so.

    As I pointed out in my first reply, your code is doing exactly what you coded (not what you think it should):
        Write one line of output (cout Hello).
        Write another line of output (cout I can).
        Write five lines of output (cout Please).
        Read the user's response (cin).
        EXIT THE PROGRAM (return)..

    Until you modify main to call myFunction, nothing you code there will ever execute and therefore have no affect on the debugger.

    Everything you show in your screen shots looks perfectly normal for the code you wrote.  If you identified what you think is missing, we may be able to tell you why.

    Monday, August 17, 2020 6:11 AM
  • No, what im saying is no matter what I type into the text editor it is not represented in the output
    Monday, August 17, 2020 6:18 AM
  • So for example I can type cout << "hello world" << endl  right in the middle of everything. It will build and save and i can visually see it in the text editor then i go to run it and that hello world is nowhere to be found in the out put window
    Monday, August 17, 2020 6:20 AM
  • Its not the code. I promise you. I can restart my computer open a brand new project that has only the word "the" in it and I will still get the output I referred to earlier. I uninstalled visual studio and still get the same output, i repaired visual studio, i still get the same out put.
    Monday, August 17, 2020 6:21 AM
  • Hi IIEleven11,

    You could modify you code, which is like this:

    void myFunction(string userAnswer);
    
    ...
    
    int main()
    {
        ...
        cin >> userAnswer;
        myFunction(userAnswer);
        return 0;
    }
    
    void myFunction(string userAnswer)
    {
        ...
    }
    
    

    Then rebuild your project to update the generated files. After that you could debug your application normally.

    Note: If there is any update in your code, please remember to rebuild your project, then debug it.

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Monday, August 17, 2020 10:11 AM