# Homework Help: Help for tomorrow's exam - program that can read in exam results

1. Apr 29, 2014

### AstroIreland

Hey guys, im studying astrophys but i have a programming module, so hopefully this is the right place to ask.

I have a few questions that I am having difficulty with so I am going to pose it in the form of a program if that's cool? I can then take it apart to see how its done.
I'd appreciate it if someone has the time!

So, I need a program that can read in exam results that are in putted (the input is in-between 0 to 100) and it is an unknown number of exam results to be inputted.
The program is to look for a repeat number that has been typed in before.

So for example the numbers may be inputted for the next 4000 years until the same two come up.
So how would I go about the program (maybe using arrays?) that can keep accepting inputs to an unknown quantity. When the matching pair of results are found, I would then like all of the user inputted results to be summed and printed to screen.

Any ideas?
Thanks in advance!

2. Apr 29, 2014

### AstroIreland

oh, it could be 4000 years or 2 minutes, its the infinite storing array until the match comes up im having issues with!

3. Apr 29, 2014

### Staff: Mentor

Your program requirements are a bit imprecise. Is this close to what you are asking?

** Sum all numbers that are input until you get a 2nd occurrance of the same number input. Numbers are between 0-100.

If so, that's pretty easy to code with finite resources (assuming the sum doesn't grow too large for the size of the summing variable).

4. Apr 29, 2014

### AstroIreland

Thanks for your quick response.
Would I just write a simple array and leave the square parenthesis without a constant?

5. Apr 29, 2014

### Staff: Mentor

I don't know what you mean by that, but I'm pretty sure the answer is no.

Do you have a particular computer language in mind for this, or is it a thought experiment to help you figure out some other problem. Even if it's a thought experiment, you should be able to write it up in pseudo-code or C.

6. Apr 29, 2014

### AstroIreland

Sorry I didnt specify the language. Yes, it's C++.
It is a question I have devised that would show me how to answer all of my coding questions within the one.
I mean for the initial coding of the array:
eg
int array [];

then the user inputs under cin (continuously until there is a repetition, then sum the numbers.

Know what I mean?

7. Apr 29, 2014

### Staff: Mentor

I'm understanding a little better, but no guarantees...

You don't need any large array to write the program the way I described it. You just need one large sum variable, and an array of ______ logical elements...

8. Apr 29, 2014

### AstroIreland

Yeah, see that's what I mean about the specific sum variable.
I want it so the user can vary e.g different schools use the program so the number of results to be in-putted is unknown.

9. Apr 29, 2014

### AstroIreland

If I get what you mean there; it's to put a large number in the array eg
int array [5000];

?

See I would like to be able to have an unknown quantity within the brackets, that does not have to be declared.

10. Apr 29, 2014

### Staff: Mentor

No, do not save the inputs. You only use them to add into an overall sum, and to check to see if they've been input previously.

You can use a large floating-point number for the sum if the number could exceed the capacity of the largest unsigned int variable for the processor you are coding for. Or you could implement your own multi-largest unsigned int variable with your own manual code for doing carrys and so on as the number gets larger. You should always put an upper bound and error checking on any kind of sum like this. A finite processor obviously does not have infinite memory resources.

11. Apr 30, 2014

### AstroIreland

Thank you for your great reply.
I have had a read over and you have filled in my missing gaps nicely.

I didn't consider large floating points. Cheers!

Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted