I am writing a program for school and am unable to get ahold of anyone to help me out.
The errors I am encountering are:
- error C2446: '<' : no conversion from 'int' to 'int *'
- error C2040: '<' : 'int [5]' differs in levels of indirection from 'int'
The same two errors are repeated throughout my code on each operator.
I have been tring to fix this problem pretty much all day, and am at wits end with it. So if you can, please help me.
I'm not looking to have the answer handed to me, I just want someone to explain it to me. That way I can avoid such a problem in the future.
My code, if necessary, is as follows.
// Start Program
#include <iostream>
using namespace std;
// Function Prototypes
void ShowSelection();
int main()
{
// Define Variables
const int Num_Males = 5, Num_Females = 5; //Set Array
int height[Num_Males][Num_Females];
int weight[Num_Males][Num_Females];
int count; // Loop counter
char choice; // States that the user will use a character for a selection
// Say hello
// Display Selection
// Get users input
cout << "Welcome!\n";
ShowSelection();
cin >> choice;
// describe each choice with case statements using the fall down method
switch (choice)
{
case 'a':
case 'A': cout << "You Chose " << Num_Males << " Males.\n";
for (int count = 0; count < Num_Males; count++)
{
cout << "Enter The Height Of Male "
<< (count + 1) << ": ";
cin >> height[count];
cout << "Enter The Weight Of Male "
<< (count + 1) << ": ";
cin >> weight[count];
cout << endl;
}
break;
case 'b':
case 'B': cout << "You Chose " << Num_Females << " Females.\n";
for (int count = 0; count < Num_Males; count++)
{
cout << "Enter The Height Of Female "
<< (count + 1) << ": ";
cin >> height[count];
The main cause of your errors is that you define height and weight as multidimensional arrays at the beginning of your main function. However you then try and insert values into them treating them as singular arrays. Such as cin >> height[count];
and if (weight[count] > 157)
You will either need to change your statments to they access the arrays correctly such as this. cin >> height[count][count] (or however you want them to be set up)
Or else change the beginning ones to singular dimensional arrays.
In this case I would think it would be easier to create a struct/class that includes both height and weight. Then create 2 singular arrays with that struct (for male and female). Then just enter in the info that way, but it depends on what you are currently learning.
Thanks a million!
That seemed to fix the errors, but still gave me a run time error. So, I'll probably have to do as you said and change the beginning of the array to singular. I appreciate your help!