Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

bravens52

macrumors regular
Original poster
Jul 16, 2009
110
0
Hey guys,
this a part of a program i am writing and i am getting a error that says : error: invalid conversion from const char to int. I dont know why i am getting this error becAUSE this is the way my college professor taught us to do it for this program and im getting this error.

does anybody know what might be wrong ?
Code:
int familyCode;

switch( familyCode )

{
	case 0:  
		return "Drake" ;
	case 1:
		return " Spencer ";
	case 2:
		return " Morgan ";
	case 3:
		return " Corinthos ";
	case 4:
		return " Webber ";
	case 5:
		return " Quartermaine ";
	case 6:
		return " Davis ";
}
 
Is there an explicit return type of char * for this function (since you didn't include all of the code)? If not, your compiler may default the return type to int, then you're returning a char *, that has to be cast to an int to match the return type.

If this isn't it, post all of your code and we'll be happy to help.

-Lee
 
This is my program..im not completely done so youre going to get more errors. Im just going through now just fixing the errors and formatting the output of the program.




Code:
/*
 CSCI 240		Program 1		Spring 2010
 
 Programmer: Jhavel Hayes
 Z-Number: 1545578
 
 Section: 3
 TA: Vikram Kumra
 
 Date Due: Mar 24, 2010
 
 Purpose: The purpose of this program is to rewrite program 4 so that it uses functions */


#include <iostream>
#include <iomanip>
#include <fstream>

using namespace std;

int buildArrays(int family[], int item[], int quantity[], double price[]);
void sortArrays( int family[], int item[], int quantity[], double price[], int numSales);
string familyName (int familyCode);
void printArrays( intfamily[], int item[], int quantity[], double price[], int numSales);

int main()

{
	int family[30], item[30], quantity[30];
	double price[30];
	int numSales;
	
	numSales=buildArrays( family, item, quantity, price);
	
	printArrays(family,item, quantity, price, numSales);
	
	sortArrays(family, item, quantity, price, numSales);
	
	printArrays(family,item, quantity, price, numSales);
	
	
		return 0;
}

int buildArrays(int family[], int item[], int quantity[], double price[])
{

ifstream inFile;

inFile.open( "input.txt" );

if ( inFile.fail() )
{
	cout << " input file did not open ";
	exit(0);
}


	int num;
	
	inFile >> num;
	
	while (inFile) 
	{
		
		double num2;
		int num;
		int sub;
		
		family[sub]=num;
		
		inFile >> num;
		item[sub] = num;
		
		inFile >> num;
		quantity[sub]= num;
		
		inFile >> num2;
		price[sub]= num2;
	
		sub++;
		
		inFile >> num;
	
	
	return sub;
}
	int familyCode;

switch( familyCode )

{
	case 0:  
		return "Drake" ;
	case 1:
		return " Spencer ";
	case 2:
		return " Morgan ";
	case 3:
		return " Corinthos ";
	case 4:
		return " Webber ";
	case 5:
		return " Quartermaine ";
	case 6:
		return " Davis ";
}

void printArrays()
{
	int numSales, item, quantity;
	
	for (int i=0; i < numSales; i++)
	{
		cout << familyName(family([i])
			<< item[i] << price[i]
			<< quanity[i] << total
			<< endl;
	}
						   
}
						   
void sortArrays()
	
		{
		
			int numSales, first, family, item, quantity;
			double price;
			double num2;
		
						   
		
			for (int i=0; i < numSales-1; i++) 
			{
				first=i;
				for (int j=0; j < numSales; j++)
				{
					if(family[j] > family[first])
						first=j;
					
				}
		 
				num2=family[first];
				family[first]=family[i];
				family[i]=num;
				
				num2=item[first];
				item[first]=item[i];
				item[i]=num;
		
				num2=price[first];
				price[first]=price[i];
				price[i]=num;
				
				num2=quantity[first];
				quantity[first]=quantity[i];
				quantity[i]=num;
			
				num2=numSales[first]
				numSales[first]=numSales[i];
				numSales[i]=num;
				
				
			}
		}
 
Your use of {}'s and ()'s is grossly unbalanced. You have missing }'s, missing )'s, and I can't even tell what else.

Clean it up, then repost it.

I already tried figuring out what it was intended to do, and clean it up from the intent, but I can't even get a clear picture of what it's intended to do.

EDIT:
Just noticed this:
Code:
Date Due: Mar 24, 2010

So, I see you still haven't learned the lesson from last time:
https://forums.macrumors.com/threads/874211/

Oh, and it looks like the reason your switch statement won't compile is because it's not defined inside a function body.

Good luck getting it done on time. I think you're gonna need it.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.