Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

I need assistance

Posted on 2000-04-26
11
Medium Priority
?
248 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 

Expert Comment

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

0
 
LVL 1

Accepted Solution

by:
Jmccp earned 200 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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 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.
Suggested Courses

636 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