C++ help!!

Discussion in 'C++' started by c++beginner, Feb 20, 2012.

  1. c++beginner

    c++beginner New Member

    Joined:
    Feb 20, 2012
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Hi, I am really struggling with this program i do not even know where to start!

    I have to make a program which will initialise an array containing the number of goals scored by a football team in each of their home games so far this season. The program has to display these numbers on the screen, then it also has to add all the goals and output the total number of goals scored.

    ANY HELP WOULD BE GREAT :shy:

    THANKS IN ADVANCE!
     
  2. Scripting

    Scripting John Hoder

    Joined:
    Jun 29, 2010
    Messages:
    421
    Likes Received:
    57
    Trophy Points:
    0
    Occupation:
    School for life
    Location:
    /root
    You want us to make your homework for you, huh? You must be kidding :D
    Show us your try, then ask for a help, show the code you already have.
     
  3. c++beginner

    c++beginner New Member

    Joined:
    Feb 20, 2012
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    this is my attempt at it but i know its very wrong lol!


    #include <iostream>

    int main ()
    {
    cout:: << "Football Team Goals" >>;
    int goals [10];
    int goals [10] = { 5, 2, 2, 1, 3,4,2,2,3,5 };

    cout:: << "total team goals:">>;

    ......................
     
  4. Scripting

    Scripting John Hoder

    Joined:
    Jun 29, 2010
    Messages:
    421
    Likes Received:
    57
    Trophy Points:
    0
    Occupation:
    School for life
    Location:
    /root
    :nonod: Oh man, do you know even the basics of C++? You should learn the basics, then try to work on ur projecs ...
     
  5. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    I'll take this a bit at a time.

    cout

    OK so far. You have to display stuff.

    ::

    Er, where did you get this from? Have you some example code from previous lessons that showed how to display stuff?

    "Football Team Goals"

    Yep, that's what you want to display.

    >>

    Er, what's this for? Are you thinking this is HTML where you have to match < and >? It isn't, and you don't. Check the hello world program, you should have seen one of these by now:
    Code:
    cout << "Hello world" << endl;
    
    int goals [10];

    Good so far.

    int goals [10]

    You don't need to do that, you've already defined goals as an int[10].

    = { 5, 2, 2, 1, 3,4,2,2,3,5 };

    Yep, that's how you initialise an array. Total code for this is
    Code:
    int goals [10]= { 5, 2, 2, 1, 3,4,2,2,3,5 };
    
    cout:: << "total team goals:">>;

    More cout confusion. Have another look at the "hello world" program.

    "The program has to display these numbers on the screen"

    OK, so you need a for() loop. Have you seen an example of this?

    "then it also has to add all the goals and output the total number of goals scored."

    OK, so before the for() loop, define a total goals variable and initialise it to zero, and within the loop add the current goal to that variable. After the loop, display the contents of that variable.

    Take it a step at a time and don't try to write the program in one go. Get the first bit working, then build and run it to make sure it works. Then add the next bit, and make sure it works, and repeat until the task is complete.
     
  6. c++beginner

    c++beginner New Member

    Joined:
    Feb 20, 2012
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    ok thanks i have managed to get this far....but now i am stuck, please tell me what i have done wrong and now what do i need to add??


    #include <iostream>
    using namespace std;
    int main()
    {
    cout << "Liverpool FC Goals:"<<endl;

    int array[4][4];
    int list [10]= { 5, 2, 2, 1, 3,4,2,2,3,5 };
    int count=0;
    for(int goals=0; goals<3; goals++)
    for(int football=0; football<3; football++)
    {
    array[goals][football]=list[count];
    count++;
    cout<<array[goals][football]<<" ";
    }

    return 0;
    }
     
  7. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Please use code tags when posting code.

    I don't know what you've done wrong because I don't know what you think the code above will do. What output did you get, and what output did you expect?
     
  8. k3y

    k3y New Member

    Joined:
    Mar 9, 2012
    Messages:
    14
    Likes Received:
    2
    Trophy Points:
    0
    Occupation:
    Student
    Code:
    #include <iostream>
    using namespace std;
    int main()
    {
        cout << "Hello, World!" << endl;
        cin.get();
        return 0;
    }
    
    That is the most basic program in C++ learn from that and see what you did wrong.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice