Why is this code with arrays not running ?

#include "stdafx.h"
#include<iostream>
using namespace std;

int get_numbers(int prompt[7], int n);

int _main()
{
int i;
for(i=0;i<=7;i++)
if(i<7);
cout << get_numbers(prompt [7]);
return 0;

}
int get_numbers(int n,int prompt[7]){
cout << "type in number";
cin >> prompt[0];
cout << "type in number";
cin >> prompt[1];
cout << "type in number";
cin >> prompt[2];
cout << "type in number";
cin >> prompt[3];
cout << "type in number";
cin >> prompt[4];
cout << "type in number";
cin >> prompt[5];
cout << "type in number";
cin >> prompt[6];

return 0;

}


There seems to be a problem with me trying to output the function or whatever.
You haven't declared prompt in main.

Try this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
int get_numbers(int p_prompt[7]); 
// I changed the name so that you wont get confused what is what.  prompt is not forward declared here and is not available to main
// You didn't call this function with the second parameter n, since it's also not used, we need to remove it.

int main()
{
  int i;
  int prompt[7]; // You need to declare the variable in main
  for (i = 0; i <7; i++) // You are simply doing something identical 7 times.  Is that intentional?
    cout << get_numbers(prompt); // pass the pointer to the function
  return 0;
}

int get_numbers(int p_prompt[7]) // I removed int n from this list because it wasn't used.
// Note that you had it in a different order than in the declaration...  that's bad.
{
  cout << "type in number";
  cin >> prompt[0];
  ...
  return 0;  // note, since you're returning 0, you will cout 0 in main.  Is this what you wanted?
}
Last edited on
Topic archived. No new replies allowed.