| | |
songa rating prog
![]() |
•
•
Join Date: Sep 2008
Posts: 4
Reputation:
Solved Threads: 0
#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
#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
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
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.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
![]() |
Other Threads in the C++ Forum
- Previous Thread: dynamic object names
- Next Thread: XP Window Hide
| Thread Tools | Search this Thread |
anyfile api array based binary bitmap c++ c++borland c/c++ char class classes code coding compile console conversion count csimilaritybetweentext delete deploy desktop developer development directshow dll download draw dynamic dynamiccharacterarray email encryption error file forms fstream function functions game gdi+ givemetehcodez gnu graph gui homeworkhelp homeworkhelper http iamthwee ibm ifstream input int integer java lib linkedlist linker loop looping loops map math matrix memory multiple news node output packing parameter pointer problem program programming project python random read recursion reference rpg string strings temperature template test text text-file tree url variable vector video visualc++ visualizationtoolkit win32 windows winsock wordfrequency wxwidgets






