Solved

I need assistance

Posted on 2000-04-26
11
201 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
Comment Utility
What is it you are trying to do ?

0
 
LVL 1

Accepted Solution

by:
Jmccp earned 50 total points
Comment Utility
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
Comment Utility
Is the main function going to be void?
0
 
LVL 1

Author Comment

by:nationnon
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Author Comment

by:nationnon
Comment Utility
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
Comment Utility
>> 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
Comment Utility
how would I find the sum in that array?  All the numbers combined?
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
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
Comment Utility
#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
Comment Utility
slavik, have you read the question history?  You shouldn't answer with information that has already been posted.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

762 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

6 Experts available now in Live!

Get 1:1 Help Now