Solved

I need assistance

Posted on 2000-04-26
11
212 Views
Last Modified: 2010-04-02
can someone give me input on how to get this thing to work?

#include <iostream.h>
#include <fstream.h>

//pototype


int num[2][7] = {0,0};



int hold[2][7];

for (int x =0; x < 2; ++x)
{
     for (int (y = 0; Y < 5; ++y)
     {
         cout << "Please enter number for position (" << x << "," << y << "): " 
         cin  >> hold [x][y];
     }
   return hold
}

0
Comment
Question by:nationnon
11 Comments
 

Expert Comment

by:AntBon
ID: 2753076
What is it you are trying to do ?

0
 
LVL 1

Accepted Solution

by:
Jmccp earned 50 total points
ID: 2753159
First of all you have a bracket before the declaration of your variable in the for loop, and the second y is capitalized and should be lower case:

     for (int y = 0; y < 5; ++y)

Secondly you are using return before the outer for loop is finishing.  This outer loop will process the inner loop and then return so it will never get to the 2nd iteration through the loop.  You need to take it out of there and do something with the hold array after the loops are finished with it.

I have the final program working correctly so far as:
-----------

#include <iostream.h>
#include <fstream.h>

int num[2][7] = {0,0};

int hold[2][7];

for (int x =0; x < 2; ++x)
{
     for (int y = 0; y < 5; ++y)
     {
         cout << "Please enter number for position (" << x << "," << y << "): ";
         cin  >> hold [x][y];
     }
}

Jim
0
 
LVL 1

Author Comment

by:nationnon
ID: 2754716
Is the main function going to be void?
0
 
LVL 1

Author Comment

by:nationnon
ID: 2754728
I need a lot more clarification on this, i'm getting 9 errors for reason's I don't know why.
0
 
LVL 22

Expert Comment

by:nietod
ID: 2754793
You need a main function.  All standard C++ programs need a main.

This code (the for loops) needs to be in a function.  All code must appear in a function.  It could be placed in the the main function.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:nationnon
ID: 2755596
where would I put 'return hold at'?  I got two errors pointing to

int num[2][7] = {0,0};

is it because i'm not using 'num' in anything?


--------------------

#include <iostream.h>
#include <fstream.h>

//Function prototypes

void main()

//Declare and initialize array

int num[2][7] = {0,0};

int hold[2][7];

//Load 14 integers into aray
for (int x =0; x < 2; ++x)
{
     for (int y = 0; y < 5; ++y)
     {
         cout << "Please enter number for position (" << x << "," << y << "): ";
         cin  >> hold [x][y];
     }
}

would return hold  go down here?

0
 
LVL 22

Expert Comment

by:nietod
ID: 2755704
>> where would I put 'return hold at'?  
Cdoes not let you pass and return arrays by value.  Which is what it seem you are trying to do.  The C way of dealing with this is for the caller to provide a pointer to an array and the function uses the pointer to fill in the array.  But I suspect you are not familiar with pointers yet.

>> would return hold  go down here?
Plus main() can only return an int,  so ther is no way (and no reason) for main() to return the array.

What do you want to do with the data that makes you want to return it?


You need to place the code in main's brackets, which you don't have, like

void main()
{
   //Declare and initialize array
   int num[2][7] = {0,0};

   *   *   *
}
0
 
LVL 1

Author Comment

by:nationnon
ID: 2755983
how would I find the sum in that array?  All the numbers combined?
0
 
LVL 22

Expert Comment

by:nietod
ID: 2756557
int main()
{

   for (int x =0; x < 2; ++x)
   {
      for (int y = 0; y < 7; ++y)
     {
        cout << "Please enter number for position (" << x << "," << y << "): ";
         cin  >> hold [x][y];
      }
   }

   int sum = 0;

   for (int x =0; x < 2; ++x)
      for (int y = 0; y < 7; ++y)
           sum = sum + hold[x][y];

   cout << "total: " << sum;

  return 0;
}
0
 

Expert Comment

by:slavik022300
ID: 2769166
#include <iostream.h>
#include <fstream.h>

int hold[2][7];

void main()
{

int x;
int y;

for (x=0; x < 2; ++x)
{
     for (y=0; y < 5; ++y)
     {
         cout << "Please enter a number for position (" << x << "," << y << "): ";
         cin  >> hold [x][y];
     }
}

//Here you can output the array for example

}
0
 
LVL 22

Expert Comment

by:nietod
ID: 2769183
slavik, have you read the question history?  You shouldn't answer with information that has already been posted.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now