songa rating prog

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2008
Posts: 4
Reputation: sinduja is an unknown quantity at this point 
Solved Threads: 0
sinduja sinduja is offline Offline
Newbie Poster

songa rating prog

 
0
  #1
Jan 3rd, 2009
#include<iostream.h>
#include<conio.h>
void main()
{
int n,i,j,t,s;
clrscr();
char sname[30],rating[60];
cout<<"enter no of songs in the list"<<endl;
cin>>n;
cout<<"enter song name and rating"<<endl;
for(i=1;i<=n;i++)
{
cin>>sname[i];
}
for(i=1;i<=n;i++)
{
cin>>rating[i];
}
cout<<"The top songs are in the order:"<<endl;
for(i=1;i<=n;i++)
{
for(j=i+1;j<=n;j++)
{
if(rating[i]<rating[j])
{
t=rating[i];
s=sname[i];
rating[i]= rating[j];
sname[i]=sname[j];
rating[j]=t;
sname[j]=s;
}
}
}
for(i=1;i<=n;i++)
{

cout<<"Name:"<<sname[i]<<"rating:"<<rating[i]<<endl;
}

getch();
}



I am a beginner in C++ n am tryin to write a prog which gets the songs name n rating as input and list the songs with greater rating in the ascending, the problem is i could input oly one character as ip for song name and i am not aware of a soln,so geeks pls help n i welcome improvisations too
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 670
Reputation: Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough 
Solved Threads: 113
Freaky_Chris's Avatar
Freaky_Chris Freaky_Chris is offline Offline
Practically a Master Poster

Re: songa rating prog

 
0
  #2
Jan 3rd, 2009
Knowledge is power -- But experience is everything
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 1,673
Reputation: vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold 
Solved Threads: 193
vmanes's Avatar
vmanes vmanes is offline Offline
Posting Virtuoso

Re: songa rating prog

 
0
  #3
Jan 3rd, 2009
Please use full words in your question, and follow the links given above to see how to better post questions here.

The main thing you need to study up on is string input and manipulation. Your array of characters is going to hold just one string (song title), not 30 of them.

Once that's done, in your sorting block, you're doing the poorest variation of selection sort, which usually works out to poorer than bubble sort. Look up code for that, and for the means to copy strings.

Lastly, your loop controls for( i = 1; i <=n; i++ ) are setting a bad habit that will come back to bite you eventually. Generally write loop for array handling as for( i = 0; i < n; i++ ) so that you use the first element of the array and will not go past its end ( assuming n elements in the array).
"We Americans got so tired of being thought of as dumb by the rest of the world that we went to the polls last November and removed all doubt."
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC