| | |
Loop help and such.
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Nov 2009
Posts: 12
Reputation:
Solved Threads: 0
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'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.
Last edited by A Tripolation; Nov 1st, 2009 at 6:06 pm.
1
#2 Nov 1st, 2009
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.:
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.:
C++ Syntax (Toggle Plain Text)
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 */ }
Last edited by niXman; Nov 1st, 2009 at 6:36 pm.
Я из Молдавии. Говорю на Русском.
•
•
Join Date: Oct 2009
Posts: 4
Reputation:
Solved Threads: 1
0
#4 Nov 1st, 2009
•
•
•
•
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.
. C++ Syntax (Toggle Plain Text)
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.
•
•
Join Date: Oct 2009
Posts: 4
Reputation:
Solved Threads: 1
0
#6 Nov 1st, 2009
•
•
•
•
Ha, no, that's not clear to me at all.
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
Last edited by SriHanuman; Nov 1st, 2009 at 7:16 pm.
•
•
Join Date: Nov 2009
Posts: 12
Reputation:
Solved Threads: 0
0
#8 Nov 1st, 2009
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.
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.
0
#9 Nov 1st, 2009
[edit]Er, wait...
Last edited by Dave Sinkula; Nov 1st, 2009 at 7:50 pm.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
0
#10 Nov 1st, 2009
The following code is unreachable:
Because you return from
An
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";
}main within the while loop.An
else doesn't have conditions like you used there. "One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
![]() |
Other Threads in the C++ Forum
- Previous Thread: i want to know......
- Next Thread: sort code & write exchange increment line
| Thread Tools | Search this Thread |
api application array arrays based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib library linkedlist linker list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg simple sorting string strings studio temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets







