| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I am new with C++, I am having problem with my homework which is now overdue. My homework problem is:
Use a single-scripted array to solve the following problem: Read in 20 numbers, each of which is between 10 & 100, inclusive. As each number is read, print only if it is not a duplicate of a number already read. Provide for the "worst case" in which all 20 numbers are different. Use the smallest possible array to solve this problem. All I have come up with is: #include <iostream>using namespace std; main(){ int a[20]; cout<<"please enter twenty numbers for between 10 & 100"<<endl; for(int i=0;i<20;i++) cin>>a[i]; cout<<"list the numbers: "; for(int i=0;i<20;i++) cout<<a[i]*<<" "; cout<<endl; } I am totally lost and my teacher couldn't stay after. I don't know where to begin, I am so confused. Help ![]() |
|
#2
|
||||
|
||||
|
I just wrote this program to figure out a decent way to do it, but I'm not going to just paste the code in (it is homework, after all). Think about the structure of the program and the order in which things need to happen. Here's some pseudocode to get you started:
Code:
- Start a loop of 20 iterations
- For each iteration:
- Take input
- Check input against valid range (between 10 and 100 inclusive)
- If in range, continue
- Check array to see if number already exists.
- If it does, print error and prompt for input again
- If it doesn't, print status/number and add number to array;
- Else request input again
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Need C++ help really badly |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|