Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   C++ help!! (http://www.go4expert.com/forums/cpp-help-t27846/)

c++beginner 21Feb2012 05:21

C++ help!!
 
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!

Scripting 21Feb2012 21:44

Re: C++ help!!
 
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.

c++beginner 21Feb2012 22:00

Re: C++ help!!
 
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 22Feb2012 01:38

Re: C++ help!!
 
:nonod: Oh man, do you know even the basics of C++? You should learn the basics, then try to work on ur projecs ...

xpi0t0s 22Feb2012 05:05

Re: C++ help!!
 
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 24Feb2012 06:45

Re: C++ help!!
 
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 24Feb2012 07:13

Re: C++ help!!
 
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 10Mar2012 00:47

Re: C++ help!!
 
Quote:

Originally Posted by c++beginner (Post 92579)
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.


All times are GMT +5.5. The time now is 09:30.