Hey all.
I'm really new to programming and would like some help, if you all don't mind ;)

I'm not actually having trouble with the programming, but rather, what I'm being asked to do.

Here is what I'm supposed to do (and yes, it is an assignment, but I'm only looking for help and not the answers):
# This program should read in 6 numbers from the keyboard and then indicate whether any of them were larger than 500 or smaller than 10. It is possible that both events (being larger than 500, being less than 10) occurred, that neither did or that only one of the two did. And it is possible that the same event happened more than once.

# First, write the program so that it reads in 6 numbers and echoes them to the screen. You must use a loop. Think about how it will be controlled.

# Then add in a flag that will detect numbers larger than 500. Use a bool variable for this.

# Then add in another flag that will detect numbers smaller than 10. Again use a bool variable.

# The feedback to the user should happen after (outside) the end of the loop, not during the input phase. The user is not interested in how many times an event occurred, only whether it happened or not. The feedback should have clear messages telling the user whether each event occurred or not; it should NOT just be the word 'true' or 'false' or 1 or 0.

could anyone tell me why I'm supposed to use a loop? And what flags are? We haven't gone over any of this at all.

Thanks for the help guys =),
Trip

Edit***
Sorry if i posted this in the wrong section.

I would have solved the problem as follows.
Create an array of objects of std:: pair <int, int>. In the loop, when you enter values would determine how to categorize this number. And on the test results would set the flag.
ex.:

typedef std::pair<int, int> item;
std::vector<item> array;
...
for ( int i = 0; i < N; i++ ) {
   std::cin >> ...
   item it;
   it.first = (value) /** fro std::cin >> */
   it.second= (expression?) /** set a flag */

}

Well we aren't allowed to use anything we haven't learned, and I most certainly haven't learned arrays.

But thank you for the help. I appreciate it.

Well we aren't allowed to use anything we haven't learned, and I most certainly haven't learned arrays.

But thank you for the help. I appreciate it.

I will just write pseudo code so you can do the assignment by yourself ;).

bool bigger;
bool smaller;
while (ii < 6)
{
    Read value from std. input;
    biger = value > 500; // flag for bigger
    smaller = value < 10; // flag for smaller
    ++ii;
}

Write message to std. output.

It is not complete but you see the idea. Hope this helps.

Ha, no, that's not clear to me at all. :D
But thanks for trying.

Ha, no, that's not clear to me at all. :D
But thanks for trying.

Hm...well just try writing it. It may take a while but you will learn something. Example is nearly done, you just need to add reading from standard input and writing to standard output. Just think about it, it will come to you ;)

2 SriHanuman
Assume that the values falling in any subcategory few, what then?

http://pastebin.com/d4f85ce82

Could anyone tell me what I'm doing wrong here?
And quite a lot of this is derived from UKmason's work. Just giving credit where it's due. ;)

[edit]Er, wait...

The following code is unreachable:

if (counter < 7 == true)
{
	cout << "Number " << counter << " is between 10 and 500" << endl; 
	cout << "Number " << counter << " is not flagged. " << endl;
}

else (counter < 7 == false);
{	
	cout << "Number " << counter << " is either less than 10 or more than 500" << endl; 
	cout << "Number " << counter << " is flagged." << endl; 
	cout << "There have been " << (flags ++) << " flags";
}

Because you return from main within the while loop.

An else doesn't have conditions like you used there.

Okay so taking the else conditions out makes it reachable?

After doing that I still cant get it to work, I dont think main is calling the while function correctly any advice?

You're going to return from main in one of two places:

int main () 
{
int number;
int counter = 0;
int flags = 1;
bool flag_none = true;
bool fag_yes = false;

	  cout << "Enter a number, hit enter to confirm, and repeat to test flags: " << endl;
      cout << endl;
    
while (counter < 7)
{	
	cin >> number;
	cout << "Echoing number, you entered " << number << endl;
	
		if (number >= 10 && number <= 500)
		{
			return true;
		}
		else
		{
			return false;
		}

counter ++;
}

if (counter < 7 == true)
{
	cout << "Number " << counter << " is between 10 and 500" << endl; 
	cout << "Number " << counter << " is not flagged. " << endl;
}

else (counter < 7 == false);
{	
	cout << "Number " << counter << " is either less than 10 or more than 500" << endl; 
	cout << "Number " << counter << " is flagged." << endl; 
	cout << "There have been " << (flags ++) << " flags";
}
}

Right?

commented: thankies +1

Ah, yes.
*smacks head*
Thanks for the help ;)

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.