Dividing Variables

Aug 6, 2008 at 1:52am
Hello I'm fairly new to this site and I've just completed my first program,got it working to a point.My problem is that I can't divide my variables here's a sample of part of my program.

I'm using string
1
2
3
4
  Average = scoreOne + scoreTwo + scoreThree / 3;


  cout << "Average is " << Average << endl; 

Right now I'm in class but will be posting the full program later tonite.

I will greatly appreciate any response from you guys also if you could reccomend some books and sites for videogame programming(C++) that be great.

Thank again.
Last edited on Aug 6, 2008 at 4:28am
Aug 6, 2008 at 2:05am
Division has a higher precedence order than addition and is therefore computed first. Your formula is equivalent to scoreOne + scoreTwo + (scoreThree / 3)
What you meant was (scoreOne + scoreTwo + scoreThree) / 3

And if you're going to post anything longer than a few lines, for the love of God, use [code] tags.
Last edited on Aug 6, 2008 at 2:55am
Aug 6, 2008 at 2:32am
Please Excuse My Dear Aunt Sally =)
a..........x..........u...i........d......u.....
r...........p..........l...v.......d......b.....
e..........o..........t....i.......i.......t.....
n..........n..........i....s.......t.......r.....
t...........e.........p....i........i.......a.......
h..........n..........l....o.......o......c........
e...........t..........i....n.......n......t..........
s...........s.........c.....................i..........
i.......................a....................o............
s.......................t....................n...........
.........................i.................................
........................o..................................
.........................n...............................
Last edited on Aug 6, 2008 at 2:33am
Aug 6, 2008 at 2:56am
Thnx guys wow i'm amazed to your guys response looking forward to trying this out can't wait to get home.

Thnx helios
one questions not sure what you mean code taggs is it the comment signs or something else

//examples of comments signs
/* original C comment signs */

Got you Mike570
its the same principal as used in Math Pemdas
thnx alot
Aug 6, 2008 at 2:56am
Thnx think i got the [code] part too
Last edited on Aug 6, 2008 at 5:21pm
Aug 6, 2008 at 3:01am
He means put [code][/code] around your code. i.e

[code]
#include <iostream>
using namespace std;

int main()
{
cout << "Hello World!" << endl;
return 0;
}
[/code]

Will turn into

1
2
3
4
5
6
7
8
#include <iostream>
using namespace std;

int main()
{
      cout << "Hello World!" << endl;
      return 0;
}
Aug 6, 2008 at 4:58am
How did you put the code tags w/o it actually turning into code...did you use HTML entities?
Aug 6, 2008 at 5:02am
You just put another tag between your [code] word so it won't be adentified as a keyword...
Example: [[b][/b]code]
(Duoas posted it here: http://www.cplusplus.com/forum/beginner/2831/ )
Last edited on Aug 6, 2008 at 5:14am
Aug 6, 2008 at 5:15am
[​code][/code]
Alright! Using zero width space (U+200B) also works.
Aug 6, 2008 at 7:37am
mikeb570: You'll want to use the [tt][/tt] tags, that will allow you to force monospace (and ASCII art will work without dots, just spaces):

Please Excuse My Dear Aunt Sally =)
a x u i d u
r p l v d b
e o t i i t
n n i s t r
t e p i i a
h n l o o c
e t i n n t
s s c i
i a o
s t n
i
o
n


Of course, you'll have to force monospace for text input fields... but I have that anyway... at least when using Camino. >_>

Edit: Helios: How would those zero width spaces work? Enlighten a poor n00b, pretty please ;)
Last edited on Aug 6, 2008 at 7:47am
Aug 6, 2008 at 2:53pm
Turn on Num Lock, hold Alt, then try pressing 8, 2, 0, 3 on the Numpad, then release Alt. You can do this to put in the decimal code for pretty much any symbol.
Aug 6, 2008 at 3:43pm
It might depend on the system, but using alt-codes above 255 doesn't work for me.
Topic archived. No new replies allowed.