Thread: array hlp
View Single Post
  #1 (permalink)  
Old January 20th, 2007, 04:09 PM
mastrgamr mastrgamr is offline
Authorized User
 
Join Date: Oct 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mastrgamr
Default array hlp

#include <ostream.h>
using namespace std;

int main() {
    int grades[5], avg, x;

    cout<<" Type in your 4 main grades: \n\n";
    cout<<"Social Studies: ";
    cin >> grades[0];
    cout<<"Math: ";
    cin >> grades[1];
    cout<<"Science: ";
    cin >> grades[2];
    cout<<"English: ";
    cin >> grades[3];

    // average them all
    avg=0;
    for(x=1; x<5; x++)
      avg += grades[x];
      avg /= 5;

    cout<<"Your Average is: "<< avg<<'\n';

    cin.get();
    return 0;
}


is there somthin wrong with this or is it that u cannot add vales to arrays?? i want the final outcome to show the average but instead it shows 502328282 y?

Mŧ~|~®GÃ(v)R~
__________________
-Stuart Smith
Reply With Quote