Solved

I need assistance

Posted on 2000-04-26
11
223 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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
 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

823 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