Current time: 22 May 2024, 12:03 PM



c++ help
Offline SmG Dragonrage

Royal Dragon
Senior Member
******
11 Years of Service
Posts: 4,018
Threads: 206
Likes Received: 0 in 0 posts
Likes Given: 0
Joined: Aug 2012
Reputation: 38
Location: Atlantis
Gavel of TrinityLeague of LegendsProgrammerCoolCrystal DonatorLegendary
#6
Re: c++ help

flash, you gotta use to the code tag around ur code otherwise it gives you cancer trying to read it.
basically for total if all the values are in the array, and you want to add them all, you do this
Code:
int array[12] myArray;
//initialize your array here
int sum = 0;
for(int i = 0; i < 12; i++)
{
       sum += myArray[i];
}
cout<<"Total: "<<sum<<endl;

and for average just use
Code:
int array[12] myArray;
//initialize your array here
int sum = 0;
for(int i = 0; i < 12; i++)
{
       sum += myArray[i];
}
float avg = sum/12.0;
cout<<"Average: "<<avg<<endl;

instead, or you can output both if you want both.
[Image: mla7mw8hs3u0g9czg.jpg?size_id=5]
Do not meddle in the affairs of Dragons, for you are crunchy and taste good with ketchup!
14 Apr 2016, 03:37 PM
Website Find Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)
SmG Gaming, © 2010-2024
Theme By: «SmG» Cloud
Edited by: «SmG» Wires