Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi. I`ve written a function and it is doesn`t work. When I try to use it, parameter of type "char*" is underlined of red color. What I should to do?

What I have tried:

C++
<pre>#include <iostream>
#include <stdlib.h>
#include <Windows.h>
#include <string>
using namespace std;

int diap(char*, int, int);

int main() {
	int const max_size = 20;
	int a[max_size];
	int size = diap("Input size-->", 0, max_size);
	return 0;
}

int diap(char* s, int low, int high)
{
	double n;
	do {
		cout << s;
		cin >> n;
	} while ((n < low) || (n > high));
	return (int)n;
}
Posted
Updated 11-Dec-21 4:47am

1 solution

C++ now enforces the use of the const qualifier on constant values> Change your function to:
C++
int diap(const char* s, int low, int high)

Also, why are you inputting double types when all your comparisons and values are int types in the rest of the program? And, finally, your call to diap in your main function captures the return value but never does anything with it.
 
Share this answer
 
Comments
JK_0809 11-Dec-21 14:40pm    
Thanks for an answer. It is just the beginning of the program. But thanks for comment, I`ll change the type
merano99 13-Dec-21 16:48pm    
Since the field starts at 0, the last index should not be larger than (max_size-1).
size = diap("Input size-->", 0, max_size-1)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900