got an Error

Expression Syntax

Page 1 of 1

4 Replies - 606 Views - Last Post: 21 February 2010 - 09:14 AM Rate Topic: -----

#1 Guest_Corrids*


Reputation:

got an Error

Posted 21 February 2010 - 08:48 AM

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#define maxS 40

int Sort_Sel,arrSize,Data[maxS];

void sortBub(int ar1[],int n1)
{
 int i1,j1;	//for loops
 int tmp1;	//for Swapping between variables

 if(n1<=1)return;	//checks if the array has only 1 variable

 i1=1;
 do
 {
  for(j1=n1-1;j1>+i1;--j1)
  {
   if(ar1[j1-1]>ar1[j1])	//if true this will perform Swapping
   {
    tmp1	=ar1[j1-1];
    ar1[j1-1]	=ar1[j1];
    ar1[j1]	=tmp1;
   }
  }
 }while(++i1<n1);
 printf("wa");
 int ctr=0;
 while(ctr<n1)
 {
  cout<<" "<<ar1[ctr];
  ctr++;
 }
}

//....................................................Main.Function..........
void main(){
	clrscr();
	cout<<"Note:Select any number not in the list to terminate Program.."<<endl;
	printf("-------------------------------------------------------------\n");
	cout<<"Select Sorting Technique:"<<endl;
	printf("\t1-Bubble Sort\n\t2-Insertion Sort\n\t3-Merge Sort\n\t4-Quick Sort\n\t5-Shell Sort\n");

	//1 Bubble Sort
	//2 Insertion Sort
	//3 Merge Sort
	//4 Quick Sort
	//5 Shell Sort
	cout<<"Enter Num:";
	cin>>Sort_Sel;

	//....................................................
	clrscr();	/*	Next Interface ^^/>,	*/

	printf("Selected Technique:");

	switch(Sort_Sel)
	{
	 case 1: 	cout<<"\tBubble Sort"<<endl; 	break;
	 case 2:	cout<<"\tInsertion Sort"<<endl;	break;
	 case 3:	cout<<"\tMerge Sort"<<endl;	break;
	 case 4:	cout<<"\tQuick Sort"<<endl;	break;
	 case 5:	cout<<"\tShell Sort"<<endl;	break;
	 default:  cout<<"\tNot in the List"<<endl;  	exit(0);	break;
	}
	//....................................................

	cout<<"Enter Array Size:";
	cin>>arrSize;
	int ctr=0;
	while(ctr<arrSize)
	{
		clrscr();
		cout<<"Enter Data["<<ctr<<"]: ";
		cin>>Data[ctr];
		ctr++;
	}
	clrscr();
	//....................................................
	ctr=0;
	cout<<"Unsorted List: ";
	if(arrSize>40){
		while(ctr<max)
		{
		cout<<Data[ctr]<<" ";
		ctr++;
		}

	}
	else{
		while(ctr<arrSize)
		{
		cout<<Data[ctr]<<" ";
		ctr++;
		}
	}
	//...................................Sorting.Process..
	switch(Sort_Sel)
	{
	 case 1:
		sortBub(Data[],arrSize);		break;
	}
	//....................................................
	getch();
}




Ive got an error on line 103....


	//...................................Sorting.Process..
	switch(Sort_Sel)
	{
	 case 1:
		sortBub(Data[],arrSize);		break;
	}
	//....................................................



How this happens??

Is This A Good Question/Topic? 0

Replies To: got an Error

#2 Anarion   User is offline

  • The Persian Coder
  • member icon

Reputation: 387
  • View blog
  • Posts: 1,663
  • Joined: 16-May 09

Re: got an Error

Posted 21 February 2010 - 08:56 AM

You missed the default case:
switch(Sort_Sel)
        {
         case 1:
                sortBub(Data[],arrSize);
                break;
         default:
                //do some desired stuff here
                break;
        }


This post has been edited by Anarion: 21 February 2010 - 08:57 AM

Was This Post Helpful? 0
  • +
  • -

#3 sarmanu   User is offline

  • D.I.C Lover
  • member icon

Reputation: 967
  • View blog
  • Posts: 2,362
  • Joined: 04-December 09

Re: got an Error

Posted 21 February 2010 - 08:57 AM

sortBub(Data[],arrSize);


That's the problem. You don't need to explicitely specify the brackets [] when passing an array. The name is enough:
sortBub(Data, arrSize); // should work


And it's "int main()", not "void main()"!!
Was This Post Helpful? 0
  • +
  • -

#4 Anarion   User is offline

  • The Persian Coder
  • member icon

Reputation: 387
  • View blog
  • Posts: 1,663
  • Joined: 16-May 09

Re: got an Error

Posted 21 February 2010 - 09:02 AM

Are you willing to use C++ at all? all of these header files are not standard:
//#include<iostream.h>
//#include<conio.h>
//#include<stdio.h>
//#include<stdlib.h>
#include<iostream>
//#include<conio.h> not in standard c++ anymore
#include<cstdio>
#include<cstdlib>


Also, why use define when you can use const ?
const int maxS = 40;


And printf is c, use cout:
std::cout<<"some text"<<std::endl;

or if you don't like using std:: everywhere, have a line like this:
using namespace std;

This post has been edited by Anarion: 21 February 2010 - 09:05 AM

Was This Post Helpful? 0
  • +
  • -

#5 Guest_Corrids*


Reputation:

Re: got an Error

Posted 21 February 2010 - 09:14 AM

I just like to experiment combinations
so i use cout and printf on same program...

by the way thanks for the replies sir..

^^
Was This Post Helpful? 0

Page 1 of 1