Solved

I need assistance

Posted on 2000-04-26
11
239 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 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
Industry Leaders: 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
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. …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

705 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