I’m having trouble with conversion. I cannot use strings in this program so I have to use char‘s – I get the error:
error C2664: 'printText' : cannot convert parameter 1 from 'const char [21]' to 'char'
1> There is no context in which this conversion is possible
I’ve tried converting it to a const pointer:
void printText(const char* text[100] = "notextgiven"...
but it doesn’t seem to help, gives me more errors than anything.
My Program:
#include <iostream>
using namespace std;
void printText(char, char, int);
int main(){
printText("I hear and I forget.", "*", 15);
}
void printText(char text[100] = "notextgiven", char symbol = ' ', int repeat = 10){
int temp = 0;
while(temp < repeat){
cout << symbol;
temp++;
}
cout << text;
temp = 0;
while(temp < repeat){
cout << symbol << endl;
temp++
}
}
This is not the right way to define your function for what you are trying to do
try this instead
this should allow your program to compile. Also change this line
to
single quotes are used for a single char variable, double quotes treat it as a string literal. As this is homework, you may have been asked to specifically use
char*but since you are using C++ in general you would be much better off usingstd::string