Write a C++ program that uses a loop to sum the array numbers by input

Write a C++ program that uses a loop to sum the array numbers by input

Page 1 of 1

1 Replies - 5002 Views - Last Post: 29 April 2008 - 12:28 PM Rate Topic: -----

#1 rise_6  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 29-April 08

Write a C++ program that uses a loop to sum the array numbers by input

Posted 29 April 2008 - 11:53 AM

Write a C++ program that uses a loop to sum the array numbers by input value from 1 to 10 and prints the result ........................................plzzzzzzzzzzzzzzzzzzzz help meeeeeeeeeeeee................help asap!

Attached File(s)


Is This A Good Question/Topic? 0
  • +

Replies To: Write a C++ program that uses a loop to sum the array numbers by input

#2 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1377
  • View blog
  • Posts: 10,951
  • Joined: 06-February 08

Re: Write a C++ program that uses a loop to sum the array numbers by input

Posted 29 April 2008 - 12:28 PM

First off, you will need an array, and an int to store the total. Then just loop through the array adding all the values to the total, like so:
// just for sake of argument, lets make an array with
// simple values in it
int array[10] = {1,2,3,4,5,6,7,8,9,10};
int total = 0; // this will be our total
for (int i = 0; i < sizeof(array); i++)
    total += array[i]; // adds the current value being read to total


Hope this helps :)

This post has been edited by gabehabe: 29 April 2008 - 12:29 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1