-
nevermind fixed it...had to tell it which header alittle differently.
also if one you gets bored, you think you could comment his code?...
I've got some of it figured out, but arrays are greek to me....
I seem to learn better from commented code and messin with it, so if someone
doesn't mind. Thanks.
-
It might be easier to just add "using namespace std;" to your code instead of all these other using statements. It'll reference stuff that you won't need, but considering that this program is just being written so you can practice and learn, it's not a huge deal at all, and, that way you won't get errors everytime you add something new to your code.
-
thats what I ended up doing
-
I'll comment his code if you promise to go and read a tutorial on C++ arrays and loops.
-
ok ok lol...I'll read on them, suggestion on source? I have a c++ by example book....helps better in some areas than others.....
-
Code:
/*
The next three lines simply include all
the necessary packages
*/
#include <iostream>
#include <string>
using namespace std;
/*
This declares a constant. Although the
two words are completely opposite, think
of a constant as a variable that never
changes
*/
const int numnames = 5;
int main()
{
/*
names is an array of strings, length is
numnames, the constant value of 5
*/
string names[numnames];
/*
for (starting values;
condition (if true, loop executes);
what to increment variables by)
{
code to execute;
}
If you have multiple starting values,
etc., you can separate them with commas.
If you have just one line in the loop,
you can omit the {}'s. Make sure you
don't have a ; after the for statement.
*/
/*
Reads in data to sort
*/
for (int c=0; c < numnames; c++)
{
cout<<"Enter Name # "<<c<<": ";
cin>>names[c];
}
/*
Main logic loop
- Compares each string
- Depending on results, will swap
strings to eventually smooth
everything into correct order
*/
for (int c1=0; c1 < numnames-1; c1++)
{
int min = c1;
/*
A nested loop - a loop inside a loop
*/
for (int c2=c1+1; c2 < numnames; c2++)
if ( names[min] > names[c2] )
min = c2;
if ( c1 != min )
names[c1].swap(names[min]);
}
/*
This loop reads out the sorted strings
*/
for ( c=0; c<numnames; c++)
cout<<names[c]<<endl;
}
Just any half-decent tutorial from Google will do. If you have a book, use that.