nationnon
asked on
I need assistance
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
}
#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
}
What is it you are trying to do ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Is the main function going to be void?
ASKER
I need a lot more clarification on this, i'm getting 9 errors for reason's I don't know why.
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.
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.
ASKER
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?
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?
>> 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};
* * *
}
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};
* * *
}
ASKER
how would I find the sum in that array? All the numbers combined?
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;
}
{
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;
}
#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
}
#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
}
slavik, have you read the question history? You shouldn't answer with information that has already been posted.