CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2012
    Posts
    2

    Help debugging if you can

    Okay, I'm just going to get this out of the way right now. I am new to C++ programming. I have done CSS and HTML and am proficient in it. But anyway, I just wrote my first program for my class. My teacher literally doesn't know what he is doing and asked students how to do it. I feel ripped off, but I am trying to learn on my own. So, Here is what I have so far.

    The program is trying to add up the 6 figures and then tell me how many figures it has added up.

    #include <iostream>
    using namespace std;

    int main ()
    {
    int X = A[X];
    float A[6]= {325.25, 154.56, 23.00, 25.25, 101.71, 400.23};
    double sum= A[0] + A[1] + A[2] + A[3] + A[4] + A[5];
    cout<< "Sum is:" <<sum<< endl;
    cout<< "amount is:" << A[X+1]<<endl;
    system("pause");
    return 0;

    }

    Any ideas on what I am doing wrong? Thank you in advance.

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Help debugging if you can

    int X = A[X];

    That makes no sense to me. What are you trying to do there?

  3. #3
    Join Date
    Sep 2012
    Posts
    2

    Re: Help debugging if you can

    I figured that if I defined that, it would relate to the A=[1], up to 6. But I guess that is not the way to do it... I think I figured it out though. This is what I have done to change it and it seems to work now.

    #include <iostream>
    using namespace std;

    int main ()
    {

    float A[6]= {325.25, 154.56, 23.00, 25.25, 101.71, 400.23};
    double sum= A[0] + A[1] + A[2] + A[3] + A[4] + A[5];
    cout<< "Sum is:" <<sum<< endl;
    cout<< "Amount is: " << sizeof A/4<<endl;
    system("pause");
    return 0;

    }

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured