Initialising an array within a for loop

All i'm trying to do is get the program to ask the person to enter a number in an array then test weather the number is between 1-50, i've tried doing it within a for loop to save time, but for some reason the if statement doesn't seem to be working

The errors I get are:

24 D:\c++\assignment 2.cpp expected `;' before '(' token

and

24 D:\c++\assignment 2.cpp expected identifier before '(' token


Line 24 is the if statement btw. Thanks for any help guys!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream.h>
#include <windows.h>

int main()

{
    char name[30];
    int number[10];
    int count;
    
    cout << "Please Enter Your Full Name: "<<endl;
    cin.getline (name,30);
    
    cout << "Please Enter 10 Numbers Between 1-50: "<<endl;
    
         
         for( count = 0; count  <= 6; count++)
         {
    
    
    
        cin>>number[count];
        
                           if (number[count] >= 1) && ( number[count] <=50)
                           {   
                               
                               count++;
                               cin>>number[count];
                           }
                               
                           else
                           {
                               cout<<"Please Restart And Enter A Valid Number";
                           }
         }
         
        



    
 system("PAUSE");
 return 0;   
}


#include<iostream>
using namespace std;

int main()

{
char name[30];
int number[10];
int count, num[10];

cout << "Please Enter Your Full Name: "<<endl;
cin.getline (name,30);

cout << "Please Enter 10 Numbers Between 1-50: "<<endl;


for( count = 0; count <= 6; count++)
{
cin>>num[count];

if (num[count] >= 1 && num[count] <=50)
{
number[count] = num[count];
}

else
{
cout<<"Please Restart And Enter A Valid Number";
}
}

system("pause");
return 0;
}

Hope this will help you
In other words (it's clearer with code tags) the parens need to surround the entire condition of the if statement. In this case, there are only two tests so each test doesn't need it's own parens.

Change this:
if (number[count] >= 1) && ( number[count] <=50)

to this
if (number[count] >= 1 && number[count] <=50)
haha thanx guys!! Usually its always a simple error, will remeber not to use double paranthesis in future =)
this can also work

if ((number[count] >= 1) && ( number[count] <=50))
Topic archived. No new replies allowed.