Archived

This topic is now archived and is closed to further replies.

SSJCORY

Only one error plz help me get around this.

Recommended Posts

The error is where i''m trying to assign: realnumber[numofnumbers] = atoi(number[numofnumbers]); That gives me an error:
C:\Program Files\Microsoft Visual Studio\MyProjects\GhettoCalcAttempt2.cpp(32) : error C2440: ''='' : cannot convert from ''int'' to ''int [100]''
        There are no conversions to array types, although there are conversions to references or pointers to arrays
Is there a way to get around this? Here is my code:
#include<iostream.h>
#include<stdlib.h>
char input[10];
int numdigits = 0;
int numofnumbers = 0;
char signs[100];
int numofsigns = 0;
char number[100][100];
int realnumber[100][100];
bool isDigit(int inquestion){
	if(input[inquestion] == ''0'' ||input[inquestion] == ''9'' ||input[inquestion] == ''8'' ||
		input[inquestion] == ''7'' ||input[inquestion] == ''6'' ||input[inquestion] == ''5'' ||
		input[inquestion] == ''4'' ||input[inquestion] == ''3'' ||input[inquestion] == ''2'' ||
		input[inquestion] == ''1''){
		return true;
	}
	else{
		return false;
	}
}
char getInputType(int inquestion){
	return input[inquestion];
}
void getInput(){
	cout<<"Input your problem:";
	cin>>input;
}
void solveProblem(){
	for(int arrayslot = 0; arrayslot < 10; arrayslot++){
		if(isDigit(arrayslot) == true){
			number[numofnumbers][numdigits] = input[arrayslot];
			realnumber[numofnumbers] = atoi(number[numofnumbers]);
			numdigits++;
		}
		if(isDigit(arrayslot) != true && numdigits > 0){
			signs[numofsigns] = getInputType(arrayslot);
			numofsigns++;
			numofnumbers++;
			numdigits = 0;
		}
	}
	cout<<realnumber[0];
	cout<<signs[0];
	cout<<realnumber[1];
}
void main(){
	getInput();
	solveProblem();
}
Thanks guys... By the way you guys in the last post I made an isdigit() function. It gave me more successefull results than my last attempt, and I believe it is more readable this way.
Favorite Quotes:Gandalf: You shall not pass!|Smeagol: We don''t need you |Smeagol: My little hobbitses.|

Share this post


Link to post
Share on other sites
I'm not sure entirly what the program is ment to do, too tired tbh! But, you can replace your isDigit fundtion to this:



bool isDigit(int inquestion)
{
if (input[inquestion] > 47 && input[inquestion] < 58) //ASCII 48 is '0', 57 is '9'

{
return true;
}
return false;
}



I believe there may be a function that does this for you, but can't remember. I think I have found the lines of code that you need to review, but not sure how you want to change them



if(isDigit(arrayslot) == true)
{
number[numofnumbers][numdigits] = input[arrayslot];
realnumber[numofnumbers] = atoi(number[numofnumbers]);
numdigits++;
}



You need to either change atoi(number[numofnumbers]) to somehting like atoi(&number[numofnumbers][numdigits]) (the & is needed as atoi takes a pointer) or you need to change number to only a one dimensional array (number[100])
Hope this helps.



[edited by - desertcube on October 20, 2003 6:00:03 PM]

Share this post


Link to post
Share on other sites
Thanx guys i figured it out. I just made that one dimensional int array 2-d with the second dimension always 0; So its the same thing as a 1-d array;
here''s the changed part:

if(isDigit(arrayslot) == true){
number[numofnumbers][numdigits] = input[arrayslot];
realnumber[numofnumbers][0] = atoi(number[numofnumbers]);
numdigits++;
}




Favorite Quotes:Gandalf: You shall not pass!|Smeagol: We don''t need you |Smeagol: My little hobbitses.|

Share this post


Link to post
Share on other sites