Należy Ci się reprymenda za nazewnictwo. Wiem, kolega już to zrobił ale ... to co Tu odstawiłeś, jest "nieludzkie" :/
Propozycja nieco lepszego udokumentowania kodu z minimalnymi poprawkami błędów i ew. nieścisłości:
#include <iostream>
#include <limits>
#include <cstddef>
static const std::size_t MAX_ELEMENTS = 5;
double * set_table(double *first_ptr, double * last_ptr);
void show_table(double *first_ptr, double * last_ptr);
void fill_table(double *first_ptr, double * last_ptr, double value);
int main()
{
double table[MAX_ELEMENTS];
double * first_ptr = table;
double * last_ptr = table + MAX_ELEMENTS;
double * range_ptr = set_table(first_ptr, last_ptr);
show_table(first_ptr, range_ptr);
if(range_ptr - first_ptr)
{
std::cout << "Podaj czynnik zmiany wartosci: ";
double value;
while(!(std::cin >> value))
{
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cout << "Niepoprawna wartosc; podaj liczbe: ";
}
fill_table(first_ptr, range_ptr, value);
show_table(first_ptr, range_ptr);
}
std::cout << "GOTOWE.\n";
}
double * set_table(double * first_ptr, double * last_ptr)
{
double temp;
int counter = 1;
for(; first_ptr < last_ptr; ++first_ptr)
{
std::cout << "Podaj wartosc nr " << counter++ << ": ";
if(!(std::cin >> temp) || (temp < 0)) {
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cout << "Bledne dane, wprowadzanie danych przerwane.\n";
break;
}
*first_ptr = temp;
}
return first_ptr;
}
void show_table(double * first_ptr, double * last_ptr)
{
for(;first_ptr < last_ptr; ++first_ptr)
{
std::cout << *first_ptr << '\n';
}
}
void fill_table(double * first_ptr, double * last_ptr, double value)
{
for(;first_ptr < last_ptr; ++first_ptr)
{
*first_ptr = value;
}
}
Dopiero teraz można zastanawiać się co z tym kodem zrobić. Co to za "Czynnik zmiany wartości"? Wartość na jaką zmienić (jak było w kodzie)?
I docelowo:
#include <iostream>
#include <limits>
#include <cstddef>
#include <string>
#include <algorithm>
#include <iterator>
static const std::size_t MAX_ELEMENTS = 5;
double * set_table(double *first_ptr, double * last_ptr);
bool read_double(double * value, const std::string& prompt, const std::string& error_msg);
int main()
{
double table[MAX_ELEMENTS];
double * first_ptr = table;
double * last_ptr = table + MAX_ELEMENTS;
double * range_ptr = set_table(first_ptr, last_ptr);
std::copy(first_ptr, range_ptr, std::ostream_iterator<double>(std::cout, "\n"));
if(range_ptr - last_ptr)
{
double value;
while(!read_double(&value,
"Podaj czynnik zmiany wartości: ",
"Niepoprawna wartość, podaj liczbę\n"));
std::fill(first_ptr, range_ptr, value);
std::copy(first_ptr, range_ptr, std::ostream_iterator<double>(std::cout, "\n"));
}
std::cout << "GOTOWE.\n";
}
double * set_table(double * first_ptr, double * last_ptr)
{
double temp;
for(std::size_t counter = 1; first_ptr < last_ptr; ++counter, ++first_ptr)
{
if(!read_double(&temp,
"Podaj wartosc nr " + std::to_string(counter) + ": ",
"Bledne dane, wprowadzanie danych przerwane.\n")
|| (temp < 0))
{
break;
}
*first_ptr = temp;
}
return first_ptr;
}
bool read_double(double * value, const std::string& prompt, const std::string& error_msg)
{
std::cout << prompt;
std::cin >> *value;
if(!std::cin) {
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cout << error_msg;
return false;
}
return true;
}