anyone know what wrong

Started by
6 comments, last by _Sigma 17 years ago
does anyone know whats wrong with this? void Difficulty(level); Invader inv[10]; int 1,2; char level; main() { cout << "Please select difficulty level 1 or 2" << endl; cin >> level; void Difficulty(level); return 0; } void difficulty(level) { if(level == 1) { for(int i = 0; i < 10; i++) { inv.setImage("C:\\2\\Hornets.gif"); inv.setVelocity(Vector2D(2,0)); Vector2D currPos = inv.getPosition(); currPos.x = currPos.x + i * 60; inv.setPosition(currPos); } } if(level == 2) { for(int i = 0; i < 10; i++) { inv.setImage("C:\\222E3\\Hornets.gif"); inv.setVelocity(Vector2D(1,0)); Vector2D currPos = inv.getPosition(); currPos.x = currPos.x + i * 60; inv.setPosition(currPos); } } } thank you. [Edited by - jadybray on April 19, 2007 5:12:43 PM]
Advertisement
1. Your function is called "difficulty", not "Difficulty". Verify the consistency between naming your functions and calling them.
2. Don't put the "void" in front of the difficulty function call. You only need the return type of a function in its signature.
3. main should have a return type of int and return 0.

Those are the three things that stick out the most, aside from the fact that you're missing #includes.
I haven't been reading your code in detail but you need
to do the following:

Put these two lines in the top of your file:

#include <iostream>
using namespace std;

that code will make the use of cout and cin possible.

I suppose that you've included the required lib(s) for Vector2D and Invader?

and you should consider writing:

int main()
{
///your code here...
return 0;
}


That's all I can see right now, hope it helps.

Good luck!
Oh, also, if "level" is a char variable, then you should be doing
level == '1'
and not
level == 1
first thing that jumps out at me is:

int 1,2;

No variable names starting with numbers.

int var_1, var_2;
would be more appropriate.

If that is all your code, you are missing includes as well. Are you getting compiler errors?
sorry I have all the #include files and classes set up properly and eveything s working fine except I keep getting this error:

error C2448: 'Difficulty' : function-style initializer appears to be a function definition

if you click on it highlights the opening brace in the function definition.
1) the declaration of the difficulty function needs to appear before main in the file

2) you declared the function with a lower case 'd' but you are calling it with an upper case 'D'. C/C++ are case sensitive. "Difficulty" is a different name than "difficulty".

-me
try this:

//assuming you have includes herevoid difficulty(char level);Invader inv[10];int var_1,var_2;char level; int main(){       cout << "Please select difficulty level 1 or 2" << endl;       cin >> level;       difficulty(level);return 0;}void difficulty(char level){       if(level == '1')       {              for(int i = 0; i < 10; i++)              {                     inv.setImage("C:\\2\\Hornets.gif");                     inv.setVelocity(Vector2D(2,0));                     Vector2D currPos = inv.getPosition();                     currPos.x = currPos.x + i * 60;                     inv.setPosition(currPos);              }       }       if(level == '2')       {              for(int i = 0; i < 10; i++)              {                     inv.setImage("C:\\222E3\\Hornets.gif");                     inv.setVelocity(Vector2D(1,0));                     Vector2D currPos = inv.getPosition();                     currPos.x = currPos.x + i * 60;                     inv.setPosition(currPos);              }       }}

This topic is closed to new replies.

Advertisement