#include "StdAfx.h"
#include <iostream>
usingnamespace std;
int main()
{
int user;
do{
cout << "Please enter any number other than 5: \t";
cin >> user;
} while (user != 5 );
cout << "Hey! you were'nt suppose to enter 5! .\n";
for (int i = 0; i <= 10; i++)
if (user[i] >= 10) //THIS IS WHERE I AM STUCK //
// ITS KINDA FRUSTRATING.I JST CANT THINK STRAIGHT //
{
cout << "wow you are more patient than i am: ";
}
return 0;
}
my problem is that i want to loop the user for 10 iterations if the user still hasn't entered 5 will tell the user "Wow, you're more patient then I am, you win." and exit.
but i am really stuck it keep saying
Error 1 error C2109: subscript requires array or pointer type c:\users\ozone\documents\visual studio 2010\projects\ozone\ozone\ozone.cpp 20
2 IntelliSense: expression must have pointer-to-object type c:\users\ozone\documents\visual studio 2010\projects\ozone\ozone\ozone.cpp 20
PLS JUST HELP ME THROUGH I CANT THINK STRAIGHT AGAIN.
THANKS
WARM REGARDS
user isn't an array. You can declare an array like this:
int Array[10];
The index range for an array is 0 : (N-1), where N is the number of elements. Also, in your for loop, the condition should be i < 10. Otherwise, you'd write beyond the array.
ozone wrote:
"PLS JUST HELP ME THROUGH I CANT THINK STRAIGHT AGAIN.
THANKS
WARM REGARDS"
IT'S NO PROBLEM, BUT CAN YOU STOP TYPING IN CAPITAL LETTERS? THANKS!
Your error comes the fact that user isn't an array. Your code doesn't do what you intend, but those loops are made just fine.
So line 9 should be int user[10];, and then make sure line 16 is set up int i = 0; i < 10; i++. Not <=, you don't want to try to get the 10th address of an array with size 10 (addresses start at zero).
the logic of Line 17 isn't quite right. I think you are confused, trying to get see if the size of the array is greater than ten. You want to check the addresses in the array to see if they equal 5. eg if (user[i] == 5)
this is the question that i was ask to do
"Write a program that ccontinues to asks the user to enter any number other than 5 until the user enters the number 5.
Then tell the user "Hey! you weren't supposed to enter 5!" and exit the program.
★ Modify the program so that after 10 iterations if the user still hasn't entered 5 will tell the user "Wow, you're more patient then I am, you win." and exit.
★★ Modify the program so that it asks the user to enter any number other than the number equal to the number of times they've been asked to enter a number. (i.e on the first iteration "Please enter any number other than 0" and on the second iteration "Please enter any number other than 1"m etc. etc. The program must behave accordingly exiting when the user enters the number they were asked not to.)"
so i was actually stuck from the modification. am sorry if am rude but you know it not easy for a newbie like you guys. so just help me out. i have tried many things but now all i know is am just typing the question ....lol.. am really a nob.
thanks
Well, this is starting to sound like something you should learn on your own (how to use loops), one thing I will say is that I wouldn't use an array at all.
@lowest tone like i said am still a newbie so please do put me through. i am just burning down my brain i cant get my self anymore. any help will be much appreciated.