I need help with simple C++ Program!!

Get help on programming - C++, Java, Delphi, etc.
Beastmunky
Registered User
Posts: 87
Joined: 05 Apr 2006, 02:00
Location: Pretoria

I need help with simple C++ Program!!

Post by Beastmunky »

Im doing a course in C++ but ive never programmed before and our lecturer sucks... we have to write a program and im stuck and cant fin any help... . Heres the assignment :
**********************************************************
Assignment D


Unit G: Do-WHILE loop structures (reference Chapter 4)
Learning Objective:
The learner must be competent in enabling a program to repeat instructions using the DO-WHILE loop structure.

Unit H: Functions (reference Chapter 5)
Learning Objective:
The learner must be competent in writing functions.



You need to produce a simple game. The nature of the game will be similar to Scorched Earth, or Gorilla. In our version there will be 2 tanks. One red tank and one blue tank. These tanks will be positioned at the bottom left and bottom right of the screen. Each player will get a chance to adjust the angle of elevation and select 1 of 5 projectile velocities. Once the projectile velocity is selected the tank fires. You then draw the projectile ( ‘*’ ) as it travels across the screen until it strikes an object, the other tank or goes off the screen. If the projectile does strike the other tank then the game is over, with the owner of that projectile being the winner. Otherwise if the projectile is off the screen or strikes the ground, then it is the other player’s chance.

The following functions need to be implemented.
• void displayTitle(): this will clear the screen, display the title of your game, the programmer that wrote the game and it will wait here until a key is pressed.
• void displayVW(): this will clear the screen, draw the ground, draw the red and blue tanks. If the projectile speed is set to -1 then it does not draw the projectile otherwise it does.
• void fseDelay(): this is a delay loop (or two) roughly about 1/10th of a second.
• int getElevVelo(int Colour, int MenuXPosition): Must display the current players Elevation in that players colour and on that players side of the screen (top left, or top right). You can increase and decrease the elevation (angle of elevation) in 1 degree steps using the arrow keys ( <- & -> ). Max & Min elevation is limited to 170 and 10 degrees respectively. This function returns the power level chosen. The power level the velocity that the projectile will initially have and is an integer number from 1 to 5. The power level options must also be displayed on the menu. If you press Esc then it must return a -1.
• int projAI(): this is the function that will draw the projectile as it moves across the screen. It will return 0 if the projectile has hit the ground or is off the sides, 1 if Red is hit and 2 if Blue is hit.
Hint: x=cos(elevation)*power. x will then be the amount of horizontal movement of the projectile per frame/loop.

The rest of the game is up to you to figure out. Such as: the elevation settings of the red and the blue players must be remembered after each turn. The projectile must travel slow enough so that it does not “jump-over” or go through the tank without touching it. The projectile can’t be drawn off the screen.


Some things you may want to add ….(not for marks).
Wind speed! – works for driftX like gravity works on driftY;
Moving tanks …

************************************************************

If theres any body that can help me PLEASE!! Ittl be much appreciated!!

Thanks!!
Moses
Registered User
Posts: 2545
Joined: 21 Jul 2004, 02:00
Location: Location:
Contact:

Post by Moses »

Why does your lecturer suck? That all seems pretty clear to me... except he's probably misusing the word 'velocity', but that's probably just me in one of my super pedantic moods.
PHR33K
Registered User
Posts: 779
Joined: 05 Sep 2004, 02:00
Contact:

Post by PHR33K »

Moses wrote:Why does your lecturer suck? That all seems pretty clear to me... except he's probably misusing the word 'velocity', but that's probably just me in one of my super pedantic moods.
Well no, he's not misusing the word "velocity" as the projectile, once in motion, would have both a direction and a magnitude.

OP: Quite frankly, I dont see what your problem is... it seems pretty straight forward to me. What exactly do you need help with? Be more specific and we might actually be able to help.
Moses
Registered User
Posts: 2545
Joined: 21 Jul 2004, 02:00
Location: Location:
Contact:

Post by Moses »

It says the player first selects the angle, and then the velocity - he probably meant 'speed'. So he is probably misusing the word 'velocity'.
Beastmunky
Registered User
Posts: 87
Joined: 05 Apr 2006, 02:00
Location: Pretoria

Post by Beastmunky »

Well implementation of those void display, void fse... all those functions.. when I compile its says the functions needs a prototype... So I guess I need to know how to make use of functions... Cant figure it out...

HELP HELP HELP HELP HELP!!!
Moses
Registered User
Posts: 2545
Joined: 21 Jul 2004, 02:00
Location: Location:
Contact:

Post by Moses »

Do you know what a prototype is? If not, read your textbook, or google it.
PHR33K
Registered User
Posts: 779
Joined: 05 Sep 2004, 02:00
Contact:

Post by PHR33K »

Beastmunky wrote:Well implementation of those void display, void fse... all those functions.. when I compile its says the functions needs a prototype... So I guess I need to know how to make use of functions... Cant figure it out...

HELP HELP HELP HELP HELP!!!
Are you asking for someone to write it for you? Because thats not going to happen. Show what you've done so far.
Beastmunky
Registered User
Posts: 87
Joined: 05 Apr 2006, 02:00
Location: Pretoria

Post by Beastmunky »

I cant figure out from the textbook how to implement functions... i just need to know how to make use of them what to define and so on ...
if i say for instance :

#include <......//what do i include//......>

void displayTitle( void );

int main ( void )

{
usedisplayTitile();
printf( "This is the Title" );


is this wrong or am I just missing somthing???
PHR33K
Registered User
Posts: 779
Joined: 05 Sep 2004, 02:00
Contact:

Post by PHR33K »

As an example:

Code: Select all

#include "stdlib.h"

void displayTitle()
{
	printf("Title\n");
	//Code goes here
}

void displayVW()
{
	//Code goes here
}

void fseDelay()
{
	//Code goes here
}

int getElevVelo(int Colour, int MenuXPosition)
{
	//Code goes here
	if ( Esc is pressed )
		return -1;
	return 0;
}

int projAI()
{
	//Code goes here
	if ( red is hit )
		return 1;
	else if ( Blue is hit) 
		return 2;

	//If it gets this far, it is assumed the projectile has either hit the ground or has gone off the side:
	return 0;
}

int main(int argc, char* argv[])
{
	//Code Goes here
	return 0;
}
Beastmunky
Registered User
Posts: 87
Joined: 05 Apr 2006, 02:00
Location: Pretoria

Post by Beastmunky »

WoW... Im really not up to spec am I??

Thanks ill be able to figure it ou im sure... I did include that stdlib header it still asked for a prototype?? maybe im just stupid....

do you know of any website where i can get like tutorials and stuff for BEGINNERS.. haha... Our textbook is a bit confusing...
CountZero
Registered User
Posts: 307
Joined: 09 Nov 2005, 02:00
Location: Behind you!

Post by CountZero »

Sorry to say this, but what have you done in the previous assignments?(as this is assignment D)

This is relatively easy. Start with the first task, clear the display and display the start screen. Do not write any of the other functions. Build the program from there.

If you did any of the other assignments this will be very easy!

BTW phreek is right, no one will write the code for you, show us what you have and we will help(I hate lazy people who want everything on a platter) :evil:

Try Google there are a lot of sites for beginners. :wink:
thealluseless
Registered User
Posts: 614
Joined: 29 Dec 2006, 02:00
Location: somewhere in the blight

Post by thealluseless »

hey man, functions are pretty simple if u understand their structure.

variable yourfunction(variables)
{
function code
}

the first variable is what ur function is returning, it must be of the same type (eg integer) as the variable u want to return

the second variables is what the function is receiving, the name does not need to be the same as the name of the varialb eu are sending it, but it does need to be of the same type..

i am actually making a mess of explaining this here, but go get yourself sams teach yourself c++ in 21 days, it is damn good, and will sort out ur basic programming issues..
I can picture in my mind a world without war, a world without hate. And I can picture us attacking that world, because they'd never expect it.
Hman
Registered User
Posts: 28520
Joined: 06 Oct 2003, 02:00
Processor: Intel i5 650
Motherboard: Asus P7H55-M LX
Graphics card: Gigabyte 7850 2GB OC
Memory: 8GB Kingston DDR3
Location: In my skin
Contact:

Re: I need help with simple C++ Program!!

Post by Hman »

Beastmunky wrote:...Unit G:...
Shouldn't this be G-Unit.
"Every thinking man is a drinking man."


Member of the Barberton Tigers
Cure
Registered User
Posts: 237
Joined: 01 Jun 2007, 02:00
Location: Cape Town

Post by Cure »

Mmm guess your not doing business C++, this does seem like a interesting assignment (far better then our boring ones). Basically its mostly just math, which is suck at, but seems as its a console so that should be easier.
User avatar
rustypup
Registered User
Posts: 8872
Joined: 13 Dec 2004, 02:00
Location: nullus pixius demonica
Contact:

Post by rustypup »

Beastmunky wrote:I did include that stdlib header it still asked for a prototype
function prototyping is one of the first things you learn about in any c++ course. along with primitive data types, control statements and the simple "Hello World" app...

you will need to declare a prototype of each of the functions prior to defining its use.

if you don't, yet, understand what prototyping is and, more importantly, why it is necessary, then you have a lot of groundwork to cover before tackling this excercise. :wink:
Most people would sooner die than think; in fact, they do so - Bertrand Russel
Cure
Registered User
Posts: 237
Joined: 01 Jun 2007, 02:00
Location: Cape Town

Post by Cure »

You really don't need function prototypes but they do make a program easier to use. It allows you to place the main 'first' but I don't think that there should be a problem with PHR33K example.
sniperx
Registered User
Posts: 466
Joined: 13 Sep 2004, 02:00
Location: Secunda
Contact:

Post by sniperx »

Hi there im doing a basic programming course and i need to write a program that ask you to enter a number of goals and cards a player got and then tells you who got more cards than goals my program is as follows but it isn't compiling correctly if anyone can assist me ill be glad




#include <iostream>
using namespace std;

void inputinformation(string names[],int goals[], int cards[])
{ for (int i =0;i <= 12; i++)
{ cout << " Enter the number of goals scored by the player : ";
cin >> goals;
cout << " Enter the number of cards received by the player : ";
cin >> cards;
}
}

//void findPlayersWithMoreCardsThanGoals (int&goals, int&cards, string namesmore)
//{
// for(int i=0,i < 12; i++)
// { if cards > goals
// }

//}

int main ()
{ const int NR_PLAYERS = 12;
string names[ ] = {"Tiny Nakedi" , "Cecil Mametsa" , "Chris Rooney" , "Mario Thomas" , "Frank Ntini" , "Charlie Ashley",
"Morio Zondo" , "Khabo Mosimane" , "Pitso Hack" , "Lloyd Mokoena" , "Rick Smith" , "Kabelo Ramago"};

int goals;
int cards;
string namesMore;

for (i=0; i < NR_PLAYERS; i++)
cout << names << "" << goals << "" << cards << "\n";


return 0;
}
Image

Download Mxit on your cell: www.mxit.co.za/wap
Zana
Registered User
Posts: 791
Joined: 25 Dec 2007, 02:00
Location: Neverland
Contact:

Post by Zana »

looks like COS101 from unisa example... but you need to have your string inputs... set right, as it will loop or go kaka..also you need to call up your functions "above" within your main function..

Look up on references: functions (how to call them up to your main function)
: strings& arrays (and strings is a type of array, an array of chars)

Code: Select all

 #include <string> 




Good luck, i had to learn the hard way ... at UNISA with no lecturer to nag, ..and had no internet.
Good luck ((^_^)) ((huggles))
:love1:
[/code]
Image
The elvin world is different from your world like our ears compared with yours.. to see all the elfs
Art Gallery: www.zananeichan.deviantart.com
sniperx
Registered User
Posts: 466
Joined: 13 Sep 2004, 02:00
Location: Secunda
Contact:

Post by sniperx »

Yes it is cos 111 from unisa but i dont know were to start
Image

Download Mxit on your cell: www.mxit.co.za/wap
Zana
Registered User
Posts: 791
Joined: 25 Dec 2007, 02:00
Location: Neverland
Contact:

Post by Zana »

sniperx wrote:Yes it is cos 111 from unisa but i dont know were to start
O.k I will give you more clues, if you cont figure it out... i might give you a working code for you... thats if i am in a good mood..

first of all you need to include the string under the includes on the top, this will give you access and utilise strings. C++ compiler you using does not have the string thing built in like chars, ints, floats, etc... and the input and output may include function like sytax, if you dont use these your program will work for the first line then all hell brakes loose..

Then in your main function you need to call up the two top functions, one is for inputing and the other is for sorting/aranging. withs orting of the names , you need to use the string functions (easier than using arrays), and UNISA recomends this.

Secondly, work through the chapters of your workbook thoroughly! (its been designed well enouph without having to research the web! I had no internet and this book was my only source of resourcing, if i can do it, so can you..) make sure you know what they are talking about.. dont copy like a parot, but follow the examples, but looks like the sorting is by integers, so it is easier than i thaught. Aslo make sure you understand trhe '&''s and []'s in the funtion headings...
The answeres are actualy in the textbook, they the examples, just the arangements, and story is different..
I copy this code... :wink: just encase, when is your assignment due?
Love and hugs
Danielle
((^_^))
Image
The elvin world is different from your world like our ears compared with yours.. to see all the elfs
Art Gallery: www.zananeichan.deviantart.com
Hex_Rated
Registered User
Posts: 3679
Joined: 19 Jan 2006, 02:00
Contact:

Post by Hex_Rated »

I don't know where to start. Dude, you need to do some studying, there are so many mistakes. I could give you a nudge in the right direction with some of the stuff but you really need to go over your basics. By writing it for you I'd be contributing you failing.

cin >> expects a string.
You can convert it to an integer with atoi.

const strings names should be global so you can prompt the user for the right player instead of the user having to guess who it is that your capturing data for. eg Cecil Mametsa is names[1] but the user can't see that. I'd suggest creating an array of a custom type (struct) instead so you can store player name, cards and goals in each record. The reason that goals and cards aren't carrying over to the next function is because they go out of scope.

For sorting the data, I recommend you use something like a bubble sort which is relatively easy to understand but the most complex part of the program. But not to fear, it's a beaten path and you should be able to find and adapt someone else's code. Quick sort is best but more complicated to sort the array. You sort the array to be a list in order of how many goals scored and then you loop through:

for(i=0;i<MAX_PLAYERS;i++)
if(Player.cards > Player.goals)
// Print the player details

Sorry, can't give you any more info. If you don't understand what I'm saying, do some serious research or maybe think of changing your degree (Is it a Bsc Comp Sci course?).

EDIT: The above snippet can be used without the aid of a bubble sort. Don't worry about sorting.
DFI LanParty X48 LT-2TR
Intel Q9450 @ 3.2Ghz
Dell 24" 2408WFP | Phillips 37" 1080p
Sapphire HD4870 X2 2GB
4GB Corsair DDR-2 1066 | Thermalrite 120 Ultra Extreme | G9 Mouse | G15 Keyboard
Vista Ultimate x64
PHR33K
Registered User
Posts: 779
Joined: 05 Sep 2004, 02:00
Contact:

Post by PHR33K »

C > C++.
Zana
Registered User
Posts: 791
Joined: 25 Dec 2007, 02:00
Location: Neverland
Contact:

Post by Zana »

PHR33K wrote:C > C++.
C++ > C# ((giggles))
Image
The elvin world is different from your world like our ears compared with yours.. to see all the elfs
Art Gallery: www.zananeichan.deviantart.com
sniperx
Registered User
Posts: 466
Joined: 13 Sep 2004, 02:00
Location: Secunda
Contact:

Post by sniperx »

Hex_Rated wrote:I don't know where to start. Dude, you need to do some studying, there are so many mistakes. I could give you a nudge in the right direction with some of the stuff but you really need to go over your basics. By writing it for you I'd be contributing you failing.

cin >> expects a string.
You can convert it to an integer with atoi.

const strings names should be global so you can prompt the user for the right player instead of the user having to guess who it is that your capturing data for. eg Cecil Mametsa is names[1] but the user can't see that. I'd suggest creating an array of a custom type (struct) instead so you can store player name, cards and goals in each record. The reason that goals and cards aren't carrying over to the next function is because they go out of scope.

For sorting the data, I recommend you use something like a bubble sort which is relatively easy to understand but the most complex part of the program. But not to fear, it's a beaten path and you should be able to find and adapt someone else's code. Quick sort is best but more complicated to sort the array. You sort the array to be a list in order of how many goals scored and then you loop through:

for(i=0;i<MAX_PLAYERS;i++)
if(Player.cards > Player.goals)
// Print the player details

Sorry, can't give you any more info. If you don't understand what I'm saying, do some serious research or maybe think of changing your degree (Is it a Bsc Comp Sci course?).

EDIT: The above snippet can be used without the aid of a bubble sort. Don't worry about sorting.


Yes i know a struct will work better but for this question I must use a one dimensional arry and thats were the problem starts.

Thanks for giving me advice it is helping and i think ill get there eventually or I hope so :roll:
Image

Download Mxit on your cell: www.mxit.co.za/wap
sniperx
Registered User
Posts: 466
Joined: 13 Sep 2004, 02:00
Location: Secunda
Contact:

Post by sniperx »

No This is for electrical engeneering why we need this I dont know bcoz i talked to a few engeneers they dont use any programming and they did visual basic or sumtin like that.
Image

Download Mxit on your cell: www.mxit.co.za/wap
Post Reply