I need help with simple C++ Program!!
-
- Registered User
- Posts: 87
- Joined: 05 Apr 2006, 02:00
- Location: Pretoria
I need help with simple C++ Program!!
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!!
**********************************************************
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!!
Well no, he's not misusing the word "velocity" as the projectile, once in motion, would have both a direction and a magnitude.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.
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.
-
- Registered User
- Posts: 87
- Joined: 05 Apr 2006, 02:00
- Location: Pretoria
Are you asking for someone to write it for you? Because thats not going to happen. Show what you've done so far.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!!!
-
- Registered User
- Posts: 87
- Joined: 05 Apr 2006, 02:00
- Location: Pretoria
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???
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???
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;
}
-
- Registered User
- Posts: 87
- Joined: 05 Apr 2006, 02:00
- Location: Pretoria
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...
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...
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)
Try Google there are a lot of sites for beginners.
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)
Try Google there are a lot of sites for beginners.
-
- Registered User
- Posts: 614
- Joined: 29 Dec 2006, 02:00
- Location: somewhere in the blight
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..
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.
-
- 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!!
Shouldn't this be G-Unit.Beastmunky wrote:...Unit G:...
"Every thinking man is a drinking man."
Member of the Barberton Tigers
Member of the Barberton Tigers
- rustypup
- Registered User
- Posts: 8872
- Joined: 13 Dec 2004, 02:00
- Location: nullus pixius demonica
- Contact:
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...Beastmunky wrote:I did include that stdlib header it still asked for a prototype
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.
Most people would sooner die than think; in fact, they do so - Bertrand Russel
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;
}
#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;
}
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)
Good luck, i had to learn the hard way ... at UNISA with no lecturer to nag, ..and had no internet.
Good luck ((^_^)) ((huggles))
[/code]
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))
[/code]
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
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..sniperx wrote:Yes it is cos 111 from unisa but i dont know were to start
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... just encase, when is your assignment due?
Love and hugs
Danielle
((^_^))
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
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.
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
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
C++ > C# ((giggles))PHR33K wrote:C > C++.
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 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