|
-
January 19th, 2011, 01:13 AM
#4
As poppy_123 mentioned the C++ syntax is nicer when using cin, unfortunately if you can only use C, then you won't be able to use it.
I also would mention that IMO using the age array like this makes more sense (replace cin, with your preference of reading user input as needed and cout with your printf command if using strictly C):
Code:
int age_count=0;
int age_needed=3;
int age[age_needed];
int age;
while (age_count < age_needed) {
cout << "Enter name for user #" << age_count+1 << ": ";
cin>>age;
if (age < 18) {
cout << "Age must be 18+\n";
}
else {
age[age_count]=age;
age_count++;
}
}
[NOTE] I didn't test the above code, so don't complain if it I made a syntax error
Last edited by ABS; January 19th, 2011 at 01:16 AM.
Similar Threads
-
By AngelicKnight in forum General Computer Discussions
Replies: 14
Last Post: June 15th, 2006, 04:04 AM
-
By IcSilk in forum Operating Systems
Replies: 8
Last Post: October 30th, 2005, 11:01 PM
-
By Tedob1 in forum Tech Humor
Replies: 0
Last Post: December 23rd, 2002, 04:58 PM
-
By Rna in forum General Programming Questions
Replies: 4
Last Post: May 22nd, 2002, 07:03 AM
-
By thesecretfire in forum Hardware
Replies: 16
Last Post: May 17th, 2002, 12:31 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|