By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,851 Members | 2,104 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,851 IT Pros & Developers. It's quick & easy.

question on array

P: 57
my question is my array is set to a size of 20 but the user can input less. I was writting if statements to get rid of the dupes and was wondering if i would have to go through it all 20 times or is there away to find the length of the array the user entered.

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3. int main() {
  4.  
  5.         int scores[20]; //array of numbers
  6.         int value;
  7.         int a_size;
  8.  
  9.         //prompt user for the list of numbers with zero being the end of the input.
  10.  
  11.         cout << "enter a list of numbers: ";
  12.         for (int i=0; i < 20; i++){
  13.  
  14.                 cin >> value;
  15.         if (value == 0)
  16.         {
  17.         break;
  18.         }
  19.         scores[i] =  value;
  20. }
  21.         if (scores[0] == scores[1]);
  22.         cout << scores[0];
  23.  
  24.         if(scores[0] == scores[2]);
  25.  
  26.  
  27. }
I was tring to write a loop to only output each number once. But was wondering if it is possible to get the size of the array or is that not neccessary.
Nov 3 '06 #1
Share this question for a faster answer!
Share on Google+

Post your reply

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