| | |
songa rating prog
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
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 |
api array based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets






