Sign in to follow this  
Wet_Water

C++ Help Please

Recommended Posts

Wet_Water    122
Heya. I'm pretty much new to the gamedev.net forums, but I've read a few things on here, and I thought I could get some help on an assignment I have in my C++ class at school. I have to create a program with something similar to the following prompt: Create a program that has a Student struct with 3 components: last name, ID number, and test grade. Create a Student type array with 5 elements for 5 students. Do not allow the user to have 2 of the same ID #'s. I thought at first that I had it all figured out, and then I ended up spending well over 6 hours trying to make it right. I did great on the inputting student information. What's stumping me is the comparing of ID numbers to see if there are any duplicates. I don't know how to do it. Here's what I've come up with in a separate program I'm doing to try and figure it out: // examination_solution.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include<conio.h> #include<iostream> using namespace std; int main() { const int MAX = 5; int idNumbers[MAX]; int x; int i; int isIdentical = 1; for(x = 0; x < MAX; ++x) { cout<<"Enter user #"<<x + 1<<"'s ID Number: "; cin>>idNumbers[x]; } for(x = 0; x < MAX; x++) { for(i = 1; i < MAX; i++) { while(isIdentical == 1) { if(idNumbers[x] == idNumbers[i]) { cout<<"User #"<<x + 1<<"s ID Number = User #"<<i + 1<<"'s ID Number."<<endl; cout<<"Enter user #"<<i + 1<<"'s number again "; cin>>idNumbers[i]; isIdentical = 1; } else isIdentical = 0; } } } for(x = 0; x < MAX; ++x) { cout<<idNumbers[x]<<endl; } getch(); } Excuse the bit of disorderliness. If anybody could help, that would be great. :)

Share this post


Link to post
Share on other sites
jyk    2094
1. Putting your code in [source] tags will preserve the code formatting, in most cases (you can edit your post using the 'edit' button in the upper right).

2. This would probably be more at home in the For Beginners forum (perhaps a mod will move it for you).

3. Strictly speaking, we're not supposed to help with homework problems here. We might be able to give you some hints or point you in the right direction though (which will be easier to do once your posted code is formatted correctly).

Share this post


Link to post
Share on other sites
Wet_Water    122
All right. I'm sorry about this. Maybe I could just leave this be then... I actually got pointed in the right direction from other sources, so I no longer need assistance. Sorry for my newbiness. :p

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this