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

  • Thread starter Thread starter AstroIreland
  • Start date Start date
  • Tags Tags
    Exam Program
AI Thread Summary
The discussion focuses on creating a C++ program to read an unknown number of exam results (0-100) and identify when a number is repeated. The user seeks guidance on using arrays to store inputs and summing them until a duplicate is found. It is suggested that instead of saving all inputs, a sum variable can be used alongside a method to check for previously entered numbers. Participants emphasize the importance of error checking and managing memory resources effectively. The conversation concludes with appreciation for the insights shared, particularly regarding the use of large floating-point numbers for summation.
AstroIreland
Messages
12
Reaction score
0
Hey guys, I am 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!
 
Physics news on Phys.org
oh, it could be 4000 years or 2 minutes, its the infinite storing array until the match comes up I am having issues with!
 
AstroIreland said:
Hey guys, I am 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!

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).
 
Thanks for your quick response.
Would I just write a simple array and leave the square parenthesis without a constant?
 
AstroIreland said:
Thanks for your quick response.
Would I just write a simple array and leave the square parenthesis without a constant?

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.
 
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?
 
AstroIreland said:
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?

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

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...
 
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.
 
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
AstroIreland said:
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.

AstroIreland said:
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.

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
berkeman said:
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.

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!
 
Back
Top