C++ help!!

c++beginner's Avatar, Join Date: Feb 2012
Newbie Member
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

THANKS IN ADVANCE!
Scripting's Avatar, Join Date: Jun 2010
John Hoder
You want us to make your homework for you, huh? You must be kidding
Show us your try, then ask for a help, show the code you already have.
c++beginner's Avatar, Join Date: Feb 2012
Newbie Member
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:">>;

......................
Scripting's Avatar, Join Date: Jun 2010
John Hoder
Oh man, do you know even the basics of C++? You should learn the basics, then try to work on ur projecs ...
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
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.
c++beginner's Avatar, Join Date: Feb 2012
Newbie Member
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;
}
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
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?
k3y's Avatar, Join Date: Mar 2012
k3y
Go4Expert Member
Quote:
Originally Posted by c++beginner View Post
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:">>;

......................
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.