I am working on a C++ program where you enter 6 integers and then use an array to store them. It then asks you to enter another integer and then reports if the last one is in the array. I have been working on it a while and I can't figure it out. I would greatly appreciate if anyone helped me figure this one out. This is what I have so far(its wrong, because when I run it, it goes into an infinite loop and ignores the yes or no answer for the first question of the program):

//Integer Reader

#include <iostream.h>
#include <cstring.h>

int main ()

    float intarray[5];
    int num1, num2, num3, num4, num5, sub;
    string reply, reply1, reply2, reply3, reply4;

cout<<"Do you want to start the program? Type yes or no and press enter."<<endl;

while (reply,reply1,reply2,reply3,reply4!= "no")

cout<<"Do you want to enter a number?"<<endl;

cout<<"Do want to enter another number?"<<endl;

cout<<"Do want to enter another number?"<<endl;

cout<<"Do want to enter another number?"<<endl;

cout<<"Do want to enter another number?"<<endl;

while (sub < 5)
{ cin>>intarray[sub];
if (sub==5)
cout<<"Enter another integer."<<endl;

return 0;

>> while (reply,reply1,reply2,reply3,reply4!= "no")

that is not necessary. just create a for loop that counts from 0 to 5 -- no need to answer that question 5 times

for(int count = 0; count < 5; count++)
   // blabla

there is no need for num1, num2 ... num5 either. just enter the numbers directly into the array. add this to the above loop

cin >> intarray;

intarray needs to be declared as an array of 6 integers, not 5

int intarray[6]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.