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 April 13th, 2006, 02:44 PM
xreddawg909x xreddawg909x is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2005
Posts: 91 xreddawg909x User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 27 m 20 sec
Reputation Power: 4
Nodetype

#include<iostream>

using namespace std;

struct nodetype
{
string name;
int ballot;
nodetype *link; // pointer to the next node
};




#include "linked.h"
#include<string>
#include<iomanip>



int main()
{
nodetype *first, *last, *newNode;
string lname, option;
int ballots;
first=NULL;
last=NULL;
int count=0;
int sum=0;




do{



cout<<"Enter name of canidate: ";
cin>>lname;
cout<<"Enter number of ballots: ";
cin>>ballots;

newNode=new nodetype;

newNode->name=lname; //place lname in name
newNode->ballot=ballots; //place ballots in ballot
newNode->link=NULL; //make sure link is empty

if(first==NULL)
{
first=newNode;
last=newNode;
}
else
{
last->link=newNode;//insert the newNode in the previous link field
last=newNode; //points to the last node in the list
}
count++;
sum=sum+ballots;
cout<<"Type '.' to finish or 'continue' to continue: "<<endl;
cin>>option;
}while(option !=".");


cout<<endl;
cout<<sum<<endl;
cout<<"There are "<<count<<" "<<"canidates"<<endl;
do
{ if (newNode == NULL)
cout << "End of list" << endl;
else
{ // Display details for what newNode points to

cout << "Name : " << newNode->name << endl;
cout << "Ballots recieved : " << newNode->ballot << endl;
cout << "Percentage of ballots : "<<fixed<<setprecision(2)<<(ballots/sum)*100<<endl;
cout << endl;

// Move to next node (if present)
newNode = newNode->link;
}
}
while (newNode != NULL);

int t;
cin>>t;


return 0;
}
.. ok i got the loop to work, but the main problem now is its only outputting the most recent node instead of outputting all of the listed any suggestions on how to dispaly ALL the nodes? or am i even making a linked list and not just overwriting info?

Reply With Quote
  #2  
Old April 13th, 2006, 08:42 PM
ubergeek ubergeek is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2005
Posts: 600 ubergeek User rank is Private First Class (20 - 50 Reputation Level)ubergeek User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 40 m 27 sec
Reputation Power: 4
Send a message via AIM to ubergeek
you are starting with newNode being the most recent node in the list. before your output loop, set newNode to first.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Nodetype


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
Stay green...Green IT