so. . . i guess you could say i'm kinda new here but. . . this site really helps me alot this past few days and i decided to join...
i was surfing all over the internet and i can't find what's the problem with my program.
this always says i need to input something inside the "[]" but i'm passing it to a function bubble sort . .. . i can't explain it well . . . i tried using quicksort but the same problem occurs. . . . can someone help me? here's the code.
#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;
int swap(int array[],int i,int j){
int temp=array[i];
array[i]=array[j];
array[j]=temp;
}
int bubblesort(int array[],int size){
int i=0;
int swapped=1;
while(swapped=1){
swapped=2;
i=0;
while(i<size-2){
if (array[i]>array[i+1]){
swap(array,i,i+1);
swapped=1;
}
i++;
}
}
}
int main()
{
int num;
int index;
index=0;
int i;
cout<<"Please enter a number."<<endl;
cin>>num;
num=0;
int size;
size=30;
int array[size];
srand((unsigned)time(0));
for(int i=0; i<size; i++){
array[i] = (rand()%30)+1;
}
i=0;
cout<<"Your random numbers are "<<endl;
while(i!=size){
while(i!=size){
cout<<array[i]<<" ";
i++;
}
}
cout<<endl;
bubblesort(array[],size);
i=size-1;
while(num<array[i]){
i--;
}
cout<<"the number lesser than "<<num;
cout<<"is "<<array[i];
system("pause");
}
the program should get a number from the user, generate 30random numbers, and then on those numbers , the program should tell the user that "this is the next lower number"
sample .. . user enters 23. . . . the program generates 24, 12, 30, 17, 21 ,6
the next lower number is 21... that's why i should sort it... but the problem is just. . . i have no idea how tofix that single problem ... . . help will be appreciated thanks. .