well, you've stumbled into the right room...
here's some starters:
a varable declaration looks like this:
Code:
type name;
//for example:
int myvariable;
basically, the types you'll most likely be using are char, int, and float. a character is a single character, like 'A','a','B', or 'b'. as you may be able to tell, an 'A' is a different character from an 'a'. an integer is a whole number without a fraction. for example, 1,2,3 are all integers, 1.2 is not. floats are used to hold fractions/decimals, but they can also be used for integers. for example, 1,2.3,4.67 are all valid floating-point numbers.
first, we'll add. generally, what's on the left of the equal sign (the lvalue) must be the variable the sum will be saved to. this variable can also be a part of the addition. here are some examples:
Code:
int a,b,c,d,e;
a=b+c; //add b and c and save it to a
a=a+d; //add a and d and save it to a
a+=e; //add a and e and save it to a
a++; //add one to a and save it to a
++a; //add one to a and save it to a
now, to count something, you will most likely use an integer and start by setting it to zero, then adding 1 to it every time something happens. a variable used like this is called an accumulator. for example:
Code:
int counter=0; //create an int called counter and set it to 0
for(int i=0;i<10;i++) //a loop structure - will go around 10 times
{
++counter; //increase counter by 1. it's the same as counter=counter+1;
}
with averages, you want to add all the values and divide by the amount there is. one simple way to do this is like this:
Code:
#include<iostream>
int main()
{
int score=0; //this will be the accumulator - start at zero
int temp; //this is to hold each individual score
int counter=0; //this is to count the nubmer of scores
for(int i=0;i<5;i++) //a loop structure - will loop 5 times
{
std::cout<<"> "; //output a prompt
std::cin>>temp; //take in an integer
std::cin.ignore(1);
score+=temp; //add the value taken in to the rest of them
counter++; //increase the number of scores taken in
}
score/=counter; //divide the total scores by the amount taken in
std::cout<<"Average: "<<score<<std::endl; //output the average
std::cin.get(); //wait for the user to press enter
return 0; //exit with a success value
}