C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old June 8th, 2004, 10:13 PM
Cris7718 Cris7718 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 1 Cris7718 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Angry Need C++ help really badly

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

Reply With Quote
  #2  
Old June 9th, 2004, 10:43 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
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

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Need C++ help really badly


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway