Dividing Variables

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
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
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
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
Thnx think i got the [code] part too
Last edited on
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;
}
How did you put the code tags w/o it actually turning into code...did you use HTML entities?
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
[​code][/code]
Alright! Using zero width space (U+200B) also works.
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
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.
It might depend on the system, but using alt-codes above 255 doesn't work for me.
Topic archived. No new replies allowed.