stuck printing values from array

This is a discussion on stuck printing values from array within the C++ Programming forums, part of the General Programming Boards category; hi, i'm trying to print the values that were entered into an array i'm stuck, can somebody plz help me ...

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    71

    stuck printing values from array

    hi,

    i'm trying to print the values that were entered into an array
    i'm stuck, can somebody plz help me out?

    thanks

    Code:
    #pragma hdrstop
    #include<iostream>
    #include<conio>
    using namespace std;
    
    //---------------------------------------------------------------------------
    #include<cstdio>
    #include<cstdlib>
    #pragma argsused
    
    int array[];
    int size;
    
    void displayArray(int nArray[], int nSize);
    
    int main(int argc, char* argv[])
    {
    
       int value;
       int numValues = 0;
       int inputValues[128];
    
       do
       {
       cout << "Enter a value into the array: ";
       cin >> value;
          if (value < 0)
          {
             break;
             }
    
       inputValues[numValues++] = value;
    
       }
       while(numValues < 128);
    
       void displayArray(int nArray[], int nSize)
    
       cout <<"The value of the array is:\n";
       for (int i=0; i<nSize; i++)
       {
    
       cout <<i<<": "<<nArray[i]<<"\n";
       }
       cout <<"\n";
       }
    
    
    
       getch();
       return 0;
    }

  2. #2
    Registered User
    Join Date
    Oct 2002
    Posts
    291
    This doesnt make sense, why do have a semi-colan at the end and what code would you like to execute inside the while loop ?
    Code:
    while(numValues < 128);
    Why have you declared a function inside main ? And where is this function displayArray ?
    Code:
    void displayArray(int nArray[], int nSize)
    hmmm.... try this code
    Code:
    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    using namespace std;
    
    int main(int argc, char* argv[])
    {
    
       int value;
       int numValues = 0;
       int inputValues[128];
    
       do
       {
             cout << "Enter a value into the array: ";
             cin >> value;
             if (value < 0)
                   break;
             
             inputValues[numValues++] = value;
       }while(1);
    
       cout <<"The value of the array is:\n";
       for (int i=0; i < numValues; i++)
       {
          cout <<i<<": "<<inputValues[i]<<"\n";
       }
       cout <<"\n";
    
       system("PAUSE");
       return 0;
    }

  3. #3
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Location
    Mt. Prospect, IL
    Posts
    2,572
    what kind of flags/arguments does your program use? Do you really need:
    Code:
    main(int argc, char* argv[])
    axon

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  4. #4
    Registered User
    Join Date
    Aug 2003
    Posts
    71
    Originally posted by laasunde
    This doesnt make sense, why do have a semi-colan at the end and what code would you like to execute inside the while loop ?
    Code:
    while(numValues < 128);
    Why have you declared a function inside main ? And where is this function displayArray ?
    Code:
    void displayArray(int nArray[], int nSize)
    hmmm.... try this code
    Code:
    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    using namespace std;
    
    int main(int argc, char* argv[])
    {
    
       int value;
       int numValues = 0;
       int inputValues[128];
    
       do
       {
             cout << "Enter a value into the array: ";
             cin >> value;
             if (value < 0)
                   break;
             
             inputValues[numValues++] = value;
       }while(1);
    
       cout <<"The value of the array is:\n";
       for (int i=0; i < numValues; i++)
       {
          cout <<i<<": "<<inputValues[i]<<"\n";
       }
       cout <<"\n";
    
       system("PAUSE");
       return 0;
    }
    i'm supposed to use a function to print a histogram where each number is represented by the number of asterisks printed on a new line.
    that's why i kind of though i need void.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  3. Eliminating duplicate values from a 20x2 array
    By desipunjabi in forum C Programming
    Replies: 2
    Last Post: 10-29-2005, 09:11 PM
  4. Inputted values into an array
    By Panther in forum C Programming
    Replies: 6
    Last Post: 04-11-2003, 10:15 AM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21