473,383 Members | 1,855 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

array question

I'm trying to find the lowest number in the array but cant seem to finish the function in the main...could some help please


Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2.  
  3. int FindLowNum(int [], int );
  4.  
  5.  
  6. int main()
  7. {
  8.  
  9.        const int arraySize = 20;
  10.  
  11.        int a[ arraySize ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
  12.  
  13.       int total = 0;
  14.  
  15.       // sum contents of array a
  16.       for ( int i = 0; i < arraySize; i++ )
  17.           total += a[ i ];
  18.  
  19.        cout << "Total of array element values is " << total << endl;
  20.  
  21.  
  22.         int FindLowNum(int a, int size);
  23.  
  24.        cout << "the lowest value is :\n"<< a;
  25.  
  26.  
  27.        return 0;  // indicates successful termination
  28.  
  29. }
  30.  
  31. int FindLowNum(int array[], int size)
  32. {
  33.   int lowest_so_far = array[0];
  34.   for (int i=1; i<size; i++)
  35.   {
  36.     if (array[i]<lowest_so_far)
  37.       lowest_so_far = array[i];
  38.   }
  39.   return lowest_so_far;
  40.  
  41. }
Oct 3 '06 #1
3 2481
ltgbau
41
see two bold command lines

Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2.  
  3. int FindLowNum(int [], int );
  4.  
  5.  
  6. int main()
  7. {
  8.  
  9.        const int arraySize = 20;
  10.  
  11.        int a[ arraySize ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
  12.  
  13.       int total = 0;
  14.  
  15.       // sum contents of array a
  16.       for ( int i = 0; i < arraySize; i++ )
  17.           total += a[ i ];
  18.  
  19.        cout << "Total of array element values is " << total << endl;
  20.  
  21.  
  22.         int n = FindLowNum(a, arraySize);
  23.  
  24.        cout << "the lowest value is :\n"<< n;
  25.  
  26.  
  27.        return 0;  // indicates successful termination
  28.  
  29. }
  30.  
  31. int FindLowNum(int array[], int size)
  32. {
  33.   int lowest_so_far = array[0];
  34.   for (int i=1; i<size; i++)
  35.   {
  36.     if (array[i]<lowest_so_far)
  37.       lowest_so_far = array[i];
  38.   }
  39.   return lowest_so_far;
  40.  
  41. }
Oct 3 '06 #2
See the highlighted line
Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2.  
  3. int FindLowNum(int [], int );
  4.  
  5.  
  6. int main()
  7. {
  8.  
  9.        const int arraySize = 20;
  10.  
  11.        int a[ arraySize ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
  12.  
  13.       int total = 0;
  14.  
  15.       // sum contents of array a
  16.       for ( int i = 0; i < arraySize; i++ )
  17.           total += a[ i ];
  18.  
  19.        cout << "Total of array element values is " << total << endl;
  20.  
  21. cout << "the lowest value is :\n"<<FindLowNum(a, arraySize);
  22.  
  23.  
  24.        return 0;  // indicates successful termination
  25.  
  26. }
  27.  
  28. int FindLowNum(int array[], int size)
  29. {
  30.   int lowest_so_far = array[0];
  31.   for (int i=1; i<size; i++)
  32.   {
  33.     if (array[i]<lowest_so_far)
  34.       lowest_so_far = array[i];
  35.   }
  36.   return lowest_so_far;
  37.  
  38. }
Oct 3 '06 #3
thank you, worked perfectly
Oct 3 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: SilverWolf | last post by:
I need some help with sorting and shuffling array of strings. I can't seem to get qsort working, and I don't even know how to start to shuffle the array. Here is what I have for now: #include...
9
by: buda | last post by:
Hi, I've been wondering for a while now (and always forgot to ask :) what is the exact quote from the Standard that forbids the use of (&array) (when x >= number_of_columns) as stated in the FAQ...
3
by: Pol Bawin | last post by:
Hi All, One : I have a property that get/set a array of an abstract class A By default my array is null In the propertygrid, It is not works correctly when my array is null. (when my array...
11
by: Geoff Cox | last post by:
Hello, I am trying to get a grip on where to place the initialization of two arrays in the code below which was created using Visual C++ 2005 Express Beta 2... private: static array<String^>^...
28
by: anonymous | last post by:
I have couple of questions related to array addresses. As they belong to the same block, I am putting them here in one single post. I hope nobody minds: char array; int address; Questions...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
51
by: Pedro Graca | last post by:
I run into a strange warning (for me) today (I was trying to improve the score of the UVA #10018 Programming Challenge). $ gcc -W -Wall -std=c89 -pedantic -O2 10018-clc.c -o 10018-clc...
7
by: heddy | last post by:
I have an array of objects. When I use Array.Resize<T>(ref Object,int Newsize); and the newsize is smaller then what the array was previously, are the resources allocated to the objects that are...
8
by: T. Wintershoven | last post by:
Hello all, I have a form with some checkboxes. The names of these checkboxes come from an array. When i click the submit button the resultcode doesn't recognize the names when i want to check...
4
by: mab464 | last post by:
I have this code on my WAMP server running on my XP machine if ( isset( $_POST ) ) { for($i=0; $i<count($_POST);$i++) { if ($ans != NULL ) $ans .= ", " . $_POST ; // Not the first...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.