#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;
}
for(i=1;i<=n;i++)
{
cin>>rating;
}
cout<<"The top songs are in the order:"<<endl;
for(i=1;i<=n;i++)
{
for(j=i+1;j<=n;j++)
{
if(rating<rating[j])
{
t=rating;
s=sname;
rating= rating[j];
sname=sname[j];
rating[j]=t;
sname[j]=s;
}
}
}
for(i=1;i<=n;i++)
{

cout<<"Name:"<<sname<<"rating:"<<rating<<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:)

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).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.