• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

Godslay

Banned
If you guys are enjoying those sample Microsoft interview questions, you'll love Cracking the Coding Interview. I've been reading it to prep for an onsite at one of the tech giants later this month.

This site has a ton of interview questions too - you can filter by company and programming language.

Read it a while back, and still go back to it from time to time. It's a good resource. The Kindle version is a little janky fyi. I have never interviewed for a tech giant, but I can tell you that similar questions appeared in a interview I had at a smaller company, so it is useful outside of that.
 

defel

Member
Another Matlab question, hoping GAF can help, its pretty simple.

Lets say I have a 2x2x2 3D matrix with

Code:
A B
C D

E F
G H

I just want to stack these guys together to get an 2*2 x 2 matrix with

Code:
A B
C D
E F
G H

obviously in this 2x2x2 example you can just plug them together but is there a quicker way to this for any 3d matrix of larger dimensions?
 

usea

Member
I hate that careercup page. It's really awful. The questions are almost entirely submitted by people who have zero regard for acceptable levels of communication. They leave out so many important details and phrase so much of it poorly that it's not even remotely useful.

Some examples:
"You came to a parking lot which is like a long road, which goes till very large length(say infinite length). Car parked on both sides of that road. You parked your car somewhere and forgot where is it. Write algirithm and then code to search your car. Note that- you dont know length of parking lot and you cant assume its length, you dont know where is your car, you are in middle of somewhere and your car might be in any side of the road"

There's so much missing from this question. In an onsite interview you could ask for more details. As a question online it's literally unanswerable. You have to make up about 100 different assumptions to even start on it.

"What happens when a URL is typed into address bar of the browser."
Seriously.

In an interview you can ask the interviewer to elaborate on their vague question. You can ask them to clarify the requirements. When you're just dumping barely-english shit into a website you need to explain everything or it's worse than useless.

/rant
 

leroidys

Member
Has anyone here interviewed with amazon? I have a phone interview (internship) with them next week and am trying to study for it.
 

usea

Member
Has anyone here interviewed with amazon? I have a phone interview (internship) with them next week and am trying to study for it.
One of my classmates did a phone interview. The only thing I remember them asking him was how he'd implement a queue using a stack, or something to that effect. Sorry I'm not much help.

If you have Introduction to Algorithms book, I think knowing that material would prepare you the best. If you can answer their algorithms and data structures question, they'll probably expand them with scaling problems like "how would you adapt your algorithm for an infinite stream of data" or "how well would this run against a distributed collection across 4 data centers?" etc.
 

Kalnos

Banned
One of my classmates did a phone interview. The only thing I remember them asking him was how he'd implement a queue using a stack, or something to that effect. Sorry I'm not much help.

If you have Introduction to Algorithms book, I think knowing that material would prepare you the best. If you can answer their algorithms and data structures question, they'll probably expand them with scaling problems like "how would you adapt your algorithm for an infinite stream of data" or "how well would this run against a distributed collection across 4 data centers?" etc.

Is that even possible without using two different stacks?
 

usea

Member
Is that even possible without using two different stacks?
Sorry for the lack of detail because I don't remember the question exactly, but when I heard the question I remember thinking that using 2 stacks was the answer. So it was probably phrased in a way that didn't eliminate that.
 

Seiki

Member
I've done an Amazon phone interview for a summer internship but didn't make it to the next round sadly. The email they sent me even recommended buying two books to help me study. They will probably throw in as many technical questions within the two 45-min phone interviews that can fit it. But the only questions I remembered are:

1) Write a function to perform integer division without using either the / or * operators.
2) Find the height of a binary tree.

They had me use http://collabedit.com/ to type in all my code. After coming out with an initial solution, they will ask you to run through some examples and if it can be optimized. Also, Big-O analysis for time and space complexity for each problem asked.

I'm a recent graduate but still looking for a job. I'm using Cracking the Coding Interview to study as well. Another book I'm using for general algorithms is The Algorithm Design Manual. This book also has nice interview questions in each chapter.
 
I've done an Amazon phone interview for a summer internship but didn't make it to the next round sadly. The email they sent me even recommended buying two books to help me study. They will probably throw in as many technical questions within the two 45-min phone interviews that can fit it. But the only questions I remembered are:

1) Write a function to perform integer division without using either the / or * operators.
2) Find the height of a binary tree.

They had me use http://collabedit.com/ to type in all my code. After coming out with an initial solution, they will ask you to run through some examples and if it can be optimized. Also, Big-O analysis for time and space complexity for each problem asked.

I'm a recent graduate but still looking for a job. I'm using Cracking the Coding Interview to study as well. Another book I'm using for general algorithms is The Algorithm Design Manual. This book also has nice interview questions in each chapter.

Hey buddy the Algorithms course just started back up on Coursera! I definitely recommend it!
 

Slavik81

Member
I hate that careercup page. It's really awful. The questions are almost entirely submitted by people who have zero regard for acceptable levels of communication. They leave out so many important details and phrase so much of it poorly that it's not even remotely useful.

Some examples:
"You came to a parking lot which is like a long road, which goes till very large length(say infinite length). Car parked on both sides of that road. You parked your car somewhere and forgot where is it. Write algirithm and then code to search your car. Note that- you dont know length of parking lot and you cant assume its length, you dont know where is your car, you are in middle of somewhere and your car might be in any side of the road"

There's so much missing from this question. In an onsite interview you could ask for more details. As a question online it's literally unanswerable. You have to make up about 100 different assumptions to even start on it.
No need to ask anything. If the street is infinitely long, the answer is obvious: you will never find your car, so give up now. On average, your car will be half-infinity away. Have fun walking.
 

Chris R

Member
Why can't Facebook, Twitter, et al make the rules easier to understand when it comes to using their trademarks and icons when linking to their sites :( don't want to get burned by breaking a rule.
 

upandaway

Member
Serialization. I'm not sure what the most common way of doing this in Java is. I would just google Java serialization.
Just practiced some serialization the other day (really only using java.io, it was simple enough) and it was the first time I ever wrote something that had influence outside of the SDE's interface. Going into the folder later and seeing a text file felt so satisfying for what was, like, 5 lines of code, haha.
 
This morning I did the tic-tac-toe evaluator to get more clojure practice in. It's pretty bad. Does anyone here who has a head for functional programming have any advice on a better way to dfs so that I can take advantage of tail call optimisation? I'm going to go back to the drawing board and try to get something more efficient but this at least does what it's meant to.

Code:
(def board [["-" "-" "-"] ["-" "-" "-"] ["-" "-" "-"]])

(defn next-player
  [this-player]
  (if (= this-player :player-o) :player-x :player-o))

(defn make-board
  [board r c player]
  (assoc board r (assoc (board r) c player)))

(defn get-col [board col] (nth board col))

(defn get-row [board row] (map #(nth % row) board))

(defn get-diags
  [board]
  (let [rng (range (count board))]
    (conj []
      (for [x (map vector rng board) :let [[i f] x]] (f i))
      (for [x (map vector (reverse rng) board) :let [[i f] x]] (f i)))))

(defn next-states
  [board player]
  (filter (complement nil?)
    (for [r (range 3) c (range 3)]
      (if (= ((board r) c) "-") (make-board board r c player)))))

(defn cost
  [board player]
  (defn row-cost [row]
    (cond
      (every? #(= % player) row) 1
      (every? #(= % (next-player player)) row) -1
      :else 0))
  (apply +
      (concat
        (map row-cost board)
        (map row-cost (map #(get-row board %) (range 3)))
        (map row-cost (get-diags board)))))

(defn minimax
  [board player]
  (defn iter [state pl]
    (let [np (next-player pl) cs (cost state player)
      nst (next-states state pl)]
      (cond
        (> cs 0) 1
        (< cs 0) -1
        (empty? nst) 0
        (= pl player) (apply max (for [s nst] (iter s np)))
        :else (apply min (for [s nst] (iter s np))))))
  (let [result (iter board player)]
    (cond
      (= result 1) player
      (= result -1) (next-player player)
      (= result 0) "draw")))

Also, I'm a member now yay!
 
I hate that careercup page. It's really awful. The questions are almost entirely submitted by people who have zero regard for acceptable levels of communication. They leave out so many important details and phrase so much of it poorly that it's not even remotely useful.

Some examples:
"You came to a parking lot which is like a long road, which goes till very large length(say infinite length). Car parked on both sides of that road. You parked your car somewhere and forgot where is it. Write algirithm and then code to search your car. Note that- you dont know length of parking lot and you cant assume its length, you dont know where is your car, you are in middle of somewhere and your car might be in any side of the road"

There's so much missing from this question. In an onsite interview you could ask for more details. As a question online it's literally unanswerable. You have to make up about 100 different assumptions to even start on it.

"What happens when a URL is typed into address bar of the browser."
Seriously.

In an interview you can ask the interviewer to elaborate on their vague question. You can ask them to clarify the requirements. When you're just dumping barely-english shit into a website you need to explain everything or it's worse than useless.

/rant
No I agree, many of the questions are poorly phrased, but that doesn't necessarily hurt the thought experiment - think about what you would need clarification on and then continue by choosing reasonable constraints for yourself to work within. Almost invariably, in an actual interview, the question will have manageable restrictions, as well. Thinking about those things helps you to really grasp the decision-making process.
 
Has anyone done development in Android with a PHP/MySQL backend?

I'm doing a coding competition in a couple of weeks and I'd like to work in Android, but one of my teammates is a php web guy. A quick search tells me that this is something people do, but I'd like to know if there are any big hurdles with that combo.
 

Yamauchi

Banned
Hey dudes and dudette(s).

Have any of you done telecommute / contractual work while living overseas? I am wondering if it is actually a viable option or an unattainable dream. I would be living in a developing, but I would still need a base income of perhaps $2500 a month -- preferably about $3000.
 

tokkun

Member
Good catch. I was going to say that the point of checking for NULL was to avoid a crash (calling free() on a hunk that's already freed WILL cause a crash with certain implementations), but the code would only change the object on the stack, not the original struct element.

Version 2:
Code:
void destroy_matrix(matrix *m) {
  if(m && m->element != NULL) // this check prevents a crash if you accidentally try to destroy the same matrix twice
  {
    free(m->element);
    m->element = NULL;
  }
}

Of course you would also need to change the call to destroy_matrix() appropriately.

It still doesn't need the check of m->element != NULL.

free(NULL) is defined as safe in the language standard, so the check does nothing in terms of correctness.

This will behave the same:

Code:
void destroy_matrix(matrix *m) {
  if (m) {
    free(m->element);
    m->element = NULL;
  }
}
 
Does Android support some kind of WLAN/Ad-hoc connectivity for multiplayer games? Need to find docs.

I know NFC works for multiplayer, a quick google search yields this. That might not be what you need, on second thought.

A quick JSON newbie question: I have data in this format:
Code:
{"cs":
    [{ 
        "time": 1094 ,
        "replaytime": 28937 ,
        "hero": "npc_dota_hero_chaos_knight",
        "kill": "npc_dota_creep_badguys_melee"
    },
    {
        "time": 1143 ,
        "replaytime": 28987 ,
        "hero": "npc_dota_hero_life_stealer",
        "kill": "npc_dota_creep_goodguys_melee"
    }
]
With a bunch more entries in that format. How do I make this into a list of objects in Python? I've tried json.load() but all that gives me is a dictionary that I don't really know how to deal with. I've read the docs, but they are not very helpful to me.
 

injurai

Banned
Any one know how to terminate a program that was executed from the Sublime Text 2 terminal. If i get an infinite loop it pretty much constitutes having to restart my system...
 

Aeana

Member
I know NFC works for multiplayer, a quick google search yields this. That might not be what you need, on second thought.

A quick JSON newbie question: I have data in this format:
Code:
{"cs":
    [{ 
        "time": 1094 ,
        "replaytime": 28937 ,
        "hero": "npc_dota_hero_chaos_knight",
        "kill": "npc_dota_creep_badguys_melee"
    },
    {
        "time": 1143 ,
        "replaytime": 28987 ,
        "hero": "npc_dota_hero_life_stealer",
        "kill": "npc_dota_creep_goodguys_melee"
    }
]
With a bunch more entries in that format. How do I make this into a list of objects in Python? I've tried json.load() but all that gives me is a dictionary that I don't really know how to deal with. I've read the docs, but they are not very helpful to me.

What do you mean you don't know how to deal with it? By default, dictionaries don't expose their keys as properties, but if you take what you quoted and use json.loads() on it, you'll get a dictionary with a single key, "cs", that contains a list of dictionaries.

So, for example,

Code:
import json

json_data = """{"cs":
    [{ 
        "time": 1094 ,
        "replaytime": 28937 ,
        "hero": "npc_dota_hero_chaos_knight",
        "kill": "npc_dota_creep_badguys_melee"
    },
    {
        "time": 1143 ,
        "replaytime": 28987 ,
        "hero": "npc_dota_hero_life_stealer",
        "kill": "npc_dota_creep_goodguys_melee"
    }
]}"""

data = json.loads(json_data)

for obj in data["cs"]:
	print obj["time"], obj["replaytime"], obj["hero"], obj["kill"]

Will output

Code:
1094 28937 npc_dota_hero_chaos_knight npc_dota_creep_badguys_melee
1143 28987 npc_dota_hero_life_stealer npc_dota_creep_goodguys_melee


If you absolutely must be able to access the keys with dot notation as with an object, then you can make a class like this.
 
What do you mean you don't know how to deal with it? By default, dictionaries don't expose their keys as properties, but if you take what you quoted and use json.loads() on it, you'll get a dictionary with a single key, "cs", that contains a list of dictionaries.

So, for example,

Code:
import json

json_data = """{"cs":
    [{ 
        "time": 1094 ,
        "replaytime": 28937 ,
        "hero": "npc_dota_hero_chaos_knight",
        "kill": "npc_dota_creep_badguys_melee"
    },
    {
        "time": 1143 ,
        "replaytime": 28987 ,
        "hero": "npc_dota_hero_life_stealer",
        "kill": "npc_dota_creep_goodguys_melee"
    }
]}"""

data = json.loads(json_data)

for obj in data["cs"]:
	print obj["time"], obj["replaytime"], obj["hero"], obj["kill"]

Will output

Code:
1094 28937 npc_dota_hero_chaos_knight npc_dota_creep_badguys_melee
1143 28987 npc_dota_hero_life_stealer npc_dota_creep_goodguys_melee


If you absolutely must be able to access the keys with dot notation as with an object, then you can make a class like this.

Oh, thanks. That's perfect. I didn't know how to index the dictionary (use "cs" as the key).
 

hateradio

The Most Dangerous Yes Man
You cannot use try/catch because c does not have exceptions.

As to your second question,
Code:
m->element = NULL;
free(m->element);
is no different from:
Code:
m->element = NULL;
free(NULL);
Pointers are values, not objects with identity. One null pointer is indistinguishable from any other of the same type. Once you've assigned null to element, you're erased the only information that could be used to free the allocated memory.
A) I thought it was C++, nvm then.
B) I figured it was the same.
 
So I cant use this. in a static?

"this" is a self-reference to the instance in languages such as C++, C#, Java. When you are in a static, you do not have an instance.

Code:
// C#

public class Foo
{
	public static void Bar()
	{
		// no access to "this" or instance methods except
		// via another instance 

		// can use Baz, a static
		Baz(); // legal
		Foo.Baz(); // also legal

		// cannot use Blah, instance method
		Blah(); // compiler error!
		this.Blah(); // compiler error

		// obtain instance, then use method on that instance
		var other = new Foo();
		other.Blah(); // legal
	}

	public static void Baz()
	{
	}

	public void Blah()
	{
	}
}
 

cyborg009

Banned
What language?


Java
"this" is a self-reference to the instance in languages such as C++, C#, Java. When you are in a static, you do not have an instance.

Code:
// C#

public class Foo
{
	public static void Bar()
	{
		// no access to "this" or instance methods except
		// via another instance 

		// can use Baz, a static
		Baz(); // legal
		Foo.Baz(); // also legal

		// cannot use Blah, instance method
		Blah(); // compiler error!
		this.Blah(); // compiler error

		// obtain instance, then use method on that instance
		var other = new Foo();
		other.Blah(); // legal
	}

	public static void Baz()
	{
	}

	public void Blah()
	{
	}
}

I'll try and see if I can some like this in Java.
 
Definitely getting a hang of the opengl api...

6rHhtjk.png


also gives me a new found respect for game engine designers.

up next make it so the blue object moves around and collision detection for the corners.

also blue object may become a circle or something more complex soon.

But damnit if having to deal with every vertex isn't a pain in the ass.

edit:

Code:
class MainDisplay
{
public:
    void myDisplay();
    void myReshape(int w, int h);
    void setWidth(int w);
    void setHeight(int h);
    int getWidth();
    int getHeight();
private:
    int width = 500;
    int height = 500;
};


int main(int argc, char** argv)
{
    MainDisplay game;
    
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
    glutInitWindowSize(game.getWidth(),game.getHeight());
    glutInitWindowPosition(0,0);
    glutCreateWindow("Board Game");
    
    glutDisplayFunc(game.myDisplay());
    //glutReshapeFunc(myReshape);
    
    glutMainLoop();
    
    
}
void MainDisplay::myDisplay()
{
    Character newchar;
    BoardClass newboard;
    
    newboard.myDisplayBoard();
    newchar.myDisplayChar();
    
}

Anyone know why glutDisplayFunc(game.myDisplay()) throws up everywhere? Unless I can't encapsulate the display callback in a class?
 

Lathentar

Looking for Pants
Definitely getting a hang of the opengl api...

6rHhtjk.png


also gives me a new found respect for game engine designers.

up next make it so the blue object moves around and collision detection for the corners.

also blue object may become a circle or something more complex soon.

But damnit if having to deal with every vertex isn't a pain in the ass.

edit:

Code:
class MainDisplay
{
public:
    void myDisplay();
    void myReshape(int w, int h);
    void setWidth(int w);
    void setHeight(int h);
    int getWidth();
    int getHeight();
private:
    int width = 500;
    int height = 500;
};


int main(int argc, char** argv)
{
    MainDisplay game;
    
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
    glutInitWindowSize(game.getWidth(),game.getHeight());
    glutInitWindowPosition(0,0);
    glutCreateWindow("Board Game");
    
    glutDisplayFunc(game.myDisplay());
    //glutReshapeFunc(myReshape);
    
    glutMainLoop();
    
    
}
void MainDisplay::myDisplay()
{
    Character newchar;
    BoardClass newboard;
    
    newboard.myDisplayBoard();
    newchar.myDisplayChar();
    
}

Anyone know why glutDisplayFunc(game.myDisplay()) throws up everywhere? Unless I can't encapsulate the display callback in a class?
You need to pass a function pointer to glut I believe. You are passing nothing.
 
Hey guys, I'm trying to wrap my head around coding in UNIX and it's driving me absolutely nuts. I've been trying to replicate a program we did in class, but every time I get some error. All it's supposed to do is create 10 files FILE01.txt FILE02.txt ...

Here's the code:

#!/bin/sh
#mkdir TestFiles
#cd TestFiles

N=0
MAX=10

while [ $N -lt $MAX ]
do
TAG='printf "%02d" $N'
touch $TAG.txt
N='expr $N + 1'
done

And here's the error it gives: If I do it as listed above...
dpl0015@dpl0015-VirtualBox:~$ ./first.sh
./first.sh: 8: [: expr: unexpected operator

And if I change the -lt to a '<' symbol
dpl0015@dpl0015-VirtualBox:~$ ./first.sh
./first.sh: 8: ./first.sh: cannot open 10: No such file

Any suggestions? This has made me appreciate Java and C++ that much more haha.
 
I know NFC works for multiplayer, a quick google search yields this. That might not be what you need, on second thought.
Thanks for the link. I actually found what I needed there (WiFi Direct).

---

I'm having issues setting up ADT at home. No matter what, ADT doesn't detect any running AVD when I try to run my app (targeted 2.2). I tried creating an AVD for 2.2 and 4.1 but they're not detected when I start them. I ran "adb devices" but it can't find any device attached (unless it's just for USB-debugging). I tried restarting ADB using kill-server and start-server but still nothing.

The odd thing is that I didn't have any issue downloading Eclipse then manually setting up Android on my work PC. I got ADT because it was supposed to be the go-to package for Android dev but it's not working out so far.

ADT does not have any trouble when I use phone though, but I really need my AVDs.

edit: After some more restarts it worked. googy pls
 

Slavik81

Member
Guess having a class function doesn't count...

Oh well. It was worth a shot.
Unfortunately not.

A couple notes:
- the syntax you are using is calling the function, not passing the function itself in.
- non-static member functions of a class must have an instance to operate on. Unfortunately, this means they are fundamentally different from static functions.
- to bridge this sort of gap, you could create a static function that has a static reference to your instance. Basically, an adapter.
 
Unfortunately not.

A couple notes:
- the syntax you are using is calling the function, not passing the function itself in.
- non-static member functions of a class must have an instance to operate on. Unfortunately, this means they are fundamentally different from static functions.
- to bridge this sort of gap, you could create a static function that has a static reference to your instance. Basically, an adapter.

Yeah that's what I eventually did. Slight pain but eh.

Also back to c++ after a year, and I have it set up like so:

Display class -> controls resolution, drawing, and keyboard interrupts.

Character class -> Character attributes, speed, position etc.

Board class -> controls objects on the board and such.

Not going overboard right? I figure that makes the most amount of sense.
 

Haly

One day I realized that sadness is just another word for not enough coffee.
God I hated OpenGL. Best of luck in your class.
 

Leucrota

Member
How would one call a private member function from another private member function in C++?

I have a function
Code:
void Turtle::ProcessInput()
{
// pre:
// post:

	char input_[ 5 ];

	inFile.getline( input_, 5, '\n');
	while( !inFile.eof() )
	{
		if( inFile.fail() )
		{
			cout << input_[] << " is not valid input.\n";
			inFile.clear();
			inFile.get();
		}
		else
		{
			EvaluateInput( input_[] ); 
		}

		inFile.getline( input_, 5, '\n' );
	}

} // end ProcessInput

Which I want to use to pass valid input to another member function EvaluateInput. How do I call that function inside the "Turtle.h" which both functions are defined in? The class is called 'Turtle'. Since you don't define an object, I am not sure how to do this and can't find any examples of it in books.
 

cyborg009

Banned
So I was trying out overloading in Java butI seem to be getting errors. But if I change one of the double to int it works.
Code:
public static double formulas(double circle){
	return Math.PI* circle *circle;		
}
	public static double formulas(double width,double length){
	return width * length;
}
	public static double formulas(double height,double radius){
		return Math.PI * radius * radius * height;
	
}
 
So I was trying out overloading in Java butI seem to be getting errors. But if I change one of the double to int it works.
Code:
	public static double formulas(double width, double length){
	return width * length;
}
	public static double formulas(double height, double radius) {
		return Math.PI * radius * radius * height;
	
}

You have two methods with the same signature. As far as method overriding goes, all that matters to the compiler is

public static *** formulas(double, double)

The parameter names are meaningless. The return type is also meaningless. You overload with differences on the number of parameters and their types.
 

cyborg009

Banned
You have two methods with the same signature. As far as method overriding goes, all that matters to the compiler is

public static *** formulas(double, double)

The parameter names are meaningless. The return type is also meaningless. You overload with differences on the number of parameters and their types.

Thanks man I understand it now.
 

Slavik81

Member
How would one call a private member function from another private member function in C++?

I have a function
Code:
void Turtle::ProcessInput()
{
// pre:
// post:

	char input_[ 5 ];

	inFile.getline( input_, 5, 'n');
	while( !inFile.eof() )
	{
		if( inFile.fail() )
		{
			cout << input_[] << " is not valid input.n";
			inFile.clear();
			inFile.get();
		}
		else
		{
			EvaluateInput( input_[] ); 
		}

		inFile.getline( input_, 5, 'n' );
	}

} // end ProcessInput

Which I want to use to pass valid input to another member function EvaluateInput. How do I call that function inside the "Turtle.h" which both functions are defined in? The class is called 'Turtle'. Since you don't define an object, I am not sure how to do this and can't find any examples of it in books.
You did it fine. If ProcessInput is a member function, it can call other member functions internally. Both ProcessInput and EvaluateInput will operate on the same instance.

I more wonder about your use of getline and input_[]. I'm pretty sure you need to drop the [] for cout and EvaluateInput. And are you sure your input buffer will be properly NULL terminated? I'd have to look up the docs for getline to tell you. Edit: seems fine to me.
Yeah that's what I eventually did. Slight pain but eh.

Also back to c++ after a year, and I have it set up like so:

Display class -> controls resolution, drawing, and keyboard interrupts.

Character class -> Character attributes, speed, position etc.

Board class -> controls objects on the board and such.

Not going overboard right? I figure that makes the most amount of sense.
That sounds reasonable for a small game. Unfortunately, I've never done any large scale game design. My work on 3d programming has been limited to very small slices of much larger problems.
 

shintoki

sparkle this bitch
I have to make a program that allows the user to select Metric or Us, then to do the calculations.

It keeps getting an error after the else statement.

#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main ()
{
//variables
double vi;
double vf;
double d;
double f;
double metric;
double us;
double x;
double y;
double unit;


//entries
cout << "Enter metric or us units";
cin >> unit;

//if statements
if (unit = metric)
{
cout << "Enter speed at impact";
cin >> vf;
cout << "Enter distance of skid mark";
cin >> d;
cout << "Enter road's coefficent of friction";
cin >> f;
x = (vf*vf) + 2 * 12.96 * d * 9.81 * f;
vi = sqrt(x);
}

else (unit = us)
{
cout << "Enter speed at impact";
cin >> vf;
cout << "Enter distance of skid mark";
cin >> d;
cout << "Enter road's coefficent of friction";
cin >> f;
x = (vf*vf) + 2 * .4649 * d * 32.2 * f;
vi = sqrt(x);
}

//Display
cout << endl << endl
<< "**********************" << endl
<< "Speed before skid:\t" << vi << endl
<< "**********************" << endl

;cout << endl;
system("pause");
return 0;

}
 

Godslay

Banned
I have to make a program that allows the user to select Metric or Us, then to do the calculations.

It keeps getting an error after the else statement.

I'm assuming the logic is carrying it to the else statement. Even with that said you have two distinct problems in that you are using an assignment statement (=) in your if and else block rather than an equivalency statement (==)s.

In simpler terms:

Code:
if(unit == metric)

and

Code:
else if(unit == us)


Give this a shot!
 
Top Bottom