| | |
Need help with an array problem
![]() |
•
•
Join Date: Apr 2006
Posts: 3
Reputation:
Solved Threads: 0
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):
C++ Syntax (Toggle Plain Text)
//Integer Reader #include <iostream.h> #include <cstring.h> int main () { float intarray[5]; int num1, num2, num3, num4, num5, sub; sub=0; string reply, reply1, reply2, reply3, reply4; cout<<"Do you want to start the program? Type yes or no and press enter."<<endl; cin>>reply; while (reply,reply1,reply2,reply3,reply4!= "no") { cout<<"Do you want to enter a number?"<<endl; cin>>reply>>num1; cout<<"Do want to enter another number?"<<endl; cin>>reply1>>num2; cout<<"Do want to enter another number?"<<endl; cin>>reply2>>num3; cout<<"Do want to enter another number?"<<endl; cin>>reply3>>num4; cout<<"Do want to enter another number?"<<endl; cin>>reply4>>num5; } while (sub < 5) { cin>>intarray[sub]; sub=sub+1; if (sub==5) cout<<"Bye"<<endl; else cout<<"Enter another integer."<<endl; } return 0; }
Last edited by Dave Sinkula; Apr 28th, 2006 at 12:09 am.
>> 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
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[i];
intarray needs to be declared as an array of 6 integers, not 5
int intarray[6]
that is not necessary. just create a for loop that counts from 0 to 5 -- no need to answer that question 5 times
C++ Syntax (Toggle Plain Text)
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[i];
intarray needs to be declared as an array of 6 integers, not 5
int intarray[6]
![]() |
Similar Threads
- Array problem (Java)
- Array problem (C++)
- Array problem (C#)
- Is there a simplest way to work this array problem? (C++)
- class array problem! (C++)
- C++ help with student array problem (C++)
- i have problem with array plz help (Java)
- Large Array Problem (PHP)
Other Threads in the C++ Forum
- Previous Thread: Please Help C++ Connect due tonight by 12
- Next Thread: Lowest Common Denominator
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ char class classes classified code coding compatible compile console conversion count date delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file filewrite forms fstream function functions game givemetehcodez graph gui homeworkhelp homeworkhelper homeworksolutions iamthwee icon if...else ifstream input int integer java lib linkedlist linker loop looping loops map math matrix memory multiple news node object output play pointer problem program programming project python random read recursion reference rpg string strings struct symbol temperature template test text text-file toolkit tree url values variable vector video win32 windows winsock wordfrequency wxwidgets






