Im currently working on this problem
Write a program that asks the user how many numbers will be entered and then has the user enter those numbers. When this is done, report to the user the position of the first 8 entered and the last 8 entered. By position we mean, for example, that if the first 8 is the 2nd number entered then its position would be 2. Turn in the following 3 outputs to demonstrate that your program works in each case.
SAMPLE OUT PUTS
How many numbers will be entered? 8
Enter num: 5
Enter num: 8
Enter num: 6
Enter num: 8
Enter num: 8
Enter num: 3
Enter num: 7
Enter num: 6
The first 8 was in position 2
The last 8 was in position 5
SAMPLE OUT PUT
How many numbers will be entered? 8
Enter num: 5
Enter num: 2
Enter num: 6
Enter num: 8
Enter num: 1
Enter num: 3
Enter num: 7
Enter num: 6
The first 8 was in position 4
The last 8 was in position 4
SAMPLEOUTPUT
How many numbers will be entered? 8
Enter num: 5
Enter num: 1
Enter num: 6
Enter num: 5
Enter num: 2
Enter num: 3
Enter num: 7
Enter num: 6
Sorry, no eights were entered.
and here is my code so far
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
|
#include <iostream>
using namespace std;
int main ()
{
int num,
nums;
char answer;
do{
cout <<"How many numbers will be entered?: "<<endl;
cin>>num;
for (int i=1;i<=num;i++){
cout<<"Enter a number: "<<endl;
cin>>nums;
while(nums==8){
cout<<"The first 8 was found in position "<<i<<endl;
break;
}
}
cout<<"Do you want to enter more numbers (Y/N)?: "<<endl;
cin>>answer;
}while ((answer=='Y') || (answer=='y'));
system ("PAUSE");
return 0;
}
| |
Currently i have it printing the position right after the 8 is stated. but my question is i don't understand how i am suppose to store the position the 8s are in or how i can have the computer skip over 8's not in the first and last position. or is it more of a problem where i need to tell the computer to GET the first and last 8 entered.
ya mainly just questions on this one, im pretty sure once i understand how i am suppose to go about it better i will be able to figure out the code.