I am trying to sort numbers entered from largest to smallest.
and i did just print the largest number entered , and the rest are left out
can anyone help me out .
#include <iostream>
#include <vector>
#include <string>
using namespace std ;
int main ()
{
vector <int> go ;
vector <int> you ;
int v ;
for (v; cin>>v;)
go.push_back(v) ;
for (int u =0 ; u<go.size() ; u++)
{
if (go[u] > go[v])
go[v] = go[u] ;
cout<<go[v]<<endl;
I suggest you try to comment your program that which command do which work.
And maybe you can make up your mind, cause your code is almost all wrong,..
and, look at your V, WT* you want it to be ? VALUE ? INDEX?
And also, format your code to be kind of something looks lovely to read it.
#include <iostream.h>
#include <conio.h>
void input(int [], int); //a function used to get 5 numbers from the user
void bubble(int [], int); //a function used to sort the numbers
void goutput(int [], int);
int main()
{
constint k=5;
int numbers[5];
clrscr(); //clears the screen
ginput(numbers, k);
bubble(numbers, k);
cout << "the sorted data are:\n";
goutput(temp, k);
getch();
return 0;
}
//functions
void ginput(int number[], int len)
{
int i;
for (i=0;i<=len;i++) {
cout << "Enter number " << (i+1) << ":";
cin >> number[i];
}
}
void bubble(int number[], int len)
{
int i, j, item;
for(i = len-1;i>0;i--)
for(j=0;j<i;j++)
if (number[j] > temp[i+1] {
item=temp[j];
number[j]=number[j+1];
number[j+1]=item;
}
}
void goutput(int number[], int len)
{
int i;
for(i=0;i<len;i++)
cout << temp[i] << " ";
}
this is the output:
Enter number 1: 25
Enter number 2: 57
Enter number 3: 48
Enter number 4: 37
Enter number 5: 12
the sorted date are:
12 25 37 48 57