Printing help

L

Latina

Hi, Can some one help to figure out why is only printing '{ }' and not
the values the user is entering?
Here is part of my code:

void IntegerSet::setString()
{
cout<<"{";
for(element=0; element<26; element++)
{
if(set[element]==true)
{
cout<<" "<<element<<" ";
}
}
cout<<"}";
}


//main
main()
{
IntegerSet run;

int temp, ele;
int newSet[26];

cout<<"\n WELCOME to the INTEGER SET PROGRAM!\n\n";
cout<<"Maximun elements in the set is 25\n";
cout<<"Enter how many elements you want in the set: ";
cin>>ele;
cout<<"Enter the values: \n";
for(int i=0; i<ele; i++)
{
cout<<i+1<<": ";
cin>>temp;
newSet=temp;
}
cout<<"Your set is: \n";
run.setString();
 
J

Jim Langston

Latina said:
Hi, Can some one help to figure out why is only printing '{ }' and not
the values the user is entering?
Here is part of my code:

void IntegerSet::setString()
{
cout<<"{";
for(element=0; element<26; element++)
{
if(set[element]==true)
{
cout<<" "<<element<<" ";
}
}
cout<<"}";
}

IntergerSet is some class. It seems to have some variable set.
//main
main()
{
IntegerSet run;

int temp, ele;
int newSet[26];

newSet is an interger array.
cout<<"\n WELCOME to the INTEGER SET PROGRAM!\n\n";
cout<<"Maximun elements in the set is 25\n";
cout<<"Enter how many elements you want in the set: ";
cin>>ele;
cout<<"Enter the values: \n";
for(int i=0; i<ele; i++)
{
cout<<i+1<<": ";
cin>>temp;
newSet=temp;


You are assigning the values to the integer array.
}
cout<<"Your set is: \n";
run.setString();

setString is working on it's array, which newSet is not a part of.
setString can't output this set becuase it doesn't see it.
 
L

Latina

Hi, Can some one help to figure out why is only printing '{ }' and not
the values the user is entering?
Here is part of my code:
void IntegerSet::setString()
{
cout<<"{";
for(element=0; element<26; element++)
{
if(set[element]==true)
{
cout<<" "<<element<<" ";
}
}
cout<<"}";
}

IntergerSet is some class. It seems to have some variable set.
//main
main()
{
IntegerSet run;
int temp, ele;
int newSet[26];

newSet is an interger array.
cout<<"\n WELCOME to the INTEGER SET PROGRAM!\n\n";
cout<<"Maximun elements in the set is 25\n";
cout<<"Enter how many elements you want in the set: ";
cin>>ele;
cout<<"Enter the values: \n";
for(int i=0; i<ele; i++)
{
cout<<i+1<<": ";
cin>>temp;
newSet=temp;


You are assigning the values to the integer array.
}
cout<<"Your set is: \n";
run.setString();

setString is working on it's array, which newSet is not a part of.
setString can't output this set becuase it doesn't see it.- Hide quoted text -

- Show quoted text -


I got it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

printing the union (help) 8
C++ program error message 4
Error message 2
I need help 1
Errors 5
CIN Input #2 gets skipped, I don't understand why. 1
Cannot find my infinite loop 1
Lexical Analysis on C++ 1

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,216
Latest member
Best cryptoconsultant

Latest Threads

Top