-2

I'm new to programming and am recently learning C++. I have a Apple laptop and it comes with Xcode. I recently started using the debugger but I don't really understand it. Is there a different view that I can debug in or does c++ always look like this when debugging? Screen Shot of code in debugger enter image description here

it's just a list of lower level language.

According to the debugger I have a problem on line 98, but my code is not even that long.

#include <iostream>
#include <fstream>
using namespace std;


ifstream infile;
int main()
{
    infile.open("number.txt");

    int x = 1, value;
    float avg, sum = 0; //numb;
    int Max, Min;

    cout <<"Enter Numbers to Calculate, type 0 when finished."<<endl<<endl;

    int numb[x-1];
    value = numb[0];

    infile >> value;


    Min = value;
    Max = value;

    while(value != 0)
    {
        infile.open("number.txt");
        sum = sum + value;
        avg = sum / x;
        x++;
        numb[x-1] = value;

        if(Max < numb[x-1] )
        {
            Max = numb[x-1];

        }
        if(Min > numb[x-1])
        {
            Min = numb[x-1];
        }
        infile >> value;

        infile.close();

    }

    cout <<"You Entered " << x-1 <<" Numbers."<<endl;
    cout <<"The Max is: "<<Max<< " The Min is: "<<Min<<endl;
    cout <<"The Sum of the Numbers is: "<<sum<<endl;
    cout <<"The Average of the Numbers is: "<<avg<<endl;

    infile.close();
    return 0;
}

this is what I'm debugging, very simple code, I just want to get the feel of the Xcode debugger. Any advice using Xcode would be great. Thank you.

  • 3
    You should fix your indenting. Poor indenting leads to a lot of code failures/bugs and makes it hard for others to read. – Error - Syntactical Remorse Aug 07 '17 at 14:17
  • Can you please elaborate a little more on the indents, I'm fairly new to coding and I have wondered how I can make my code easier to read. What are some of the tips you use to make the code better visually? – Jerry Berry Aug 07 '17 at 14:20
  • This one of the better styles [wiki](https://en.wikipedia.org/wiki/Indent_style#Allman_style) – Error - Syntactical Remorse Aug 07 '17 at 14:21
  • `int numb[x-1];` isn't very meaningful when `x` is a value you won't determine until later. (`x` is 1 when you're declaring `numb`. Think about what that means.) You don't need an array for any of the values you're computing, though. – molbdnilo Aug 07 '17 at 14:24
  • And no, it shouldn't look like that. It should look like source code. There's a setting or menu item somewhere. – molbdnilo Aug 07 '17 at 14:25
  • ok so I can probably just read in the values from my numbers.txt file and find the average or the Max/Min without using and array, that's a good tip keeping the code simple. – Jerry Berry Aug 07 '17 at 14:30

1 Answers1

0

What you are seeing is the Disassembly of your code. For reference assembly is a "low-level symbolic code converted by an assembler" and a nasty language to program in. Seeing the assembly is an advanced way to debug that not many people use anymore. There is already a question regarding this please look at XCode Debugger: Why is it only showing me assembler?

  • Excellent! thank you very much Alex G 1. I learned that particular view is called the assembly of the code 2. I fixed the issue 3. I will look into better formatting my code based go your wiki reference. – Jerry Berry Aug 07 '17 at 14:40
  • @JerryBerry I formatted your code in the question take a took at that for example. Feel free to mark this as an answer if it worked for you. – Error - Syntactical Remorse Aug 07 '17 at 14:44