I get an error message \" Error2440: \'=\' : cannot convert from \'double*\' to
ID: 3615157 • Letter: I
Question
I get an error message "Error2440: '=' : cannot convert from 'double*' to 'char*' "my programis:
#include<iostream> using namespacestd;
//FunctionPrototypes void getString(char*, int);
intmain() { const int SIZE =81; char*sentence; // To dynamically allocate an array
// Get String getString(sentence,SIZE);
system("pause"); return0; }
void getString (char*sentence, int SIZE) { int num,count; // Getthe number of days of sales. cout<< "How many sentences do you wish "; cout<< "to enter? "; cin>> num;
//Dynamically allocate an array large enough to hold allsentence sentence= new double[num];
// Getthe sales figures for each day. cout << "Enter thesentence! "; for(count = 0; count < SIZE; count++) { cout<< "Sentence " << (count + 1) << ":"; cin.getline(sentence,SIZE); cin.ignore();
}
// Freedynamically allocated memory delete[] sentence; sentence= 0; // Make sales point to null.
}
my programis:
#include<iostream> using namespacestd;
//FunctionPrototypes void getString(char*, int);
intmain() { const int SIZE =81; char*sentence; // To dynamically allocate an array
// Get String getString(sentence,SIZE);
system("pause"); return0; }
void getString (char*sentence, int SIZE) { int num,count; // Getthe number of days of sales. cout<< "How many sentences do you wish "; cout<< "to enter? "; cin>> num;
//Dynamically allocate an array large enough to hold allsentence sentence= new double[num];
// Getthe sales figures for each day. cout << "Enter thesentence! "; for(count = 0; count < SIZE; count++) { cout<< "Sentence " << (count + 1) << ":"; cin.getline(sentence,SIZE); cin.ignore();
}
// Freedynamically allocated memory delete[] sentence; sentence= 0; // Make sales point to null.
}
#include<iostream> using namespacestd;
//FunctionPrototypes void getString(char*, int);
intmain() { const int SIZE =81; char*sentence; // To dynamically allocate an array
// Get String getString(sentence,SIZE);
system("pause"); return0; }
void getString (char*sentence, int SIZE) { int num,count; // Getthe number of days of sales. cout<< "How many sentences do you wish "; cout<< "to enter? "; cin>> num;
//Dynamically allocate an array large enough to hold allsentence sentence= new double[num];
// Getthe sales figures for each day. cout << "Enter thesentence! "; for(count = 0; count < SIZE; count++) { cout<< "Sentence " << (count + 1) << ":"; cin.getline(sentence,SIZE); cin.ignore();
}
// Freedynamically allocated memory delete[] sentence; sentence= 0; // Make sales point to null.
}
Explanation / Answer
#include<iostream>
using namespace std;
//Function Prototypes
void getString(char *, int);
int main()
{
const int SIZE = 81;
char *sentence; // To dynamically allocate anarray
// Get String
getString(sentence,SIZE);
system("pause");
return 0;
}
void getString (char*sentence, int SIZE)
{
int num, count;
// Get the number of days of sales.
cout << "How many sentences do you wish";
cout << "to enter? ";
cin >> num;
//Dynamically allocate an array large enough to hold all sentence
sentence = newchar[num];
// Getthe sales figures for each day.
cout << "Enter the sentence! ";
for (count = 0; count < SIZE; count++)
{
cout << "Sentence " << (count + 1)<< ": ";
cin.getline(sentence,SIZE);
cin.ignore();
}
// Free dynamically allocated memory
delete [] sentence;
sentence = 0; // Make sales point tonull.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.