I am getting an error: In function `void delete_repeats(char*, int&)\': 50 C:\\D
ID: 3617510 • Letter: I
Question
I am getting an error: In function `void delete_repeats(char*, int&)': 50 C:Dev-Cppch7_pp2.cpp `position_used' undeclared (firstuse this function) (Each undeclared identifier is reported only once for eachfunction it appears in.) 52 C:Dev-Cppch7_pp2.cpp name lookup of `i' changed for newISO `for' scoping 50 C:Dev-Cppch7_pp2.cpp using obsolete binding at`i'Here is the program:
#include <iostream> //function prototypes void delete_repeats(char a[], int& size); bool find_char (char target, char a[], int size);
int main() {
using namespace std; char a[81] = "mary had a little lamb. its fleecewas white as snow."; int size = 53;//sample main character size53
cout << "Before: size = " << size<< " array = " << endl; for (int i=0; i<size; i++)//output beforesize { cout << a[i];//outputs allcharacters } cout << endl;
delete_repeats(a,size);//deletesrepeat
cout << "After: size = "<< size<< "array = " << endl; for (int i=0; i<size; i++)//output after newsize { cout << a[i];//output after removingextra characters, spaces } cout << endl; return 0; }
// search array a[] for char target, up to indexsize-1. // If found, return true. Otherwise return false.
bool find_char (char target, char a[], int size)
{ for (int i=0; i < size; i++) { if (a[i] == target) return true; } return false; } //Delete repeat characters from a[] and return // the new size in position_used. void delete_repeats(char a[], int& positions_used) { int new_size = 0; for (int i = 0; i < position_used; i++) { if (!find_char(a[i], a, new_size)) { a[new_size] = a[i]; new_size++; } } position_used = new_size; } In function `void delete_repeats(char*, int&)': 50 C:Dev-Cppch7_pp2.cpp `position_used' undeclared (firstuse this function) (Each undeclared identifier is reported only once for eachfunction it appears in.) 52 C:Dev-Cppch7_pp2.cpp name lookup of `i' changed for newISO `for' scoping 50 C:Dev-Cppch7_pp2.cpp using obsolete binding at`i'
Here is the program:
#include <iostream> //function prototypes void delete_repeats(char a[], int& size); bool find_char (char target, char a[], int size);
int main() {
using namespace std; char a[81] = "mary had a little lamb. its fleecewas white as snow."; int size = 53;//sample main character size53
cout << "Before: size = " << size<< " array = " << endl; for (int i=0; i<size; i++)//output beforesize { cout << a[i];//outputs allcharacters } cout << endl;
delete_repeats(a,size);//deletesrepeat
cout << "After: size = "<< size<< "array = " << endl; for (int i=0; i<size; i++)//output after newsize { cout << a[i];//output after removingextra characters, spaces } cout << endl; return 0; }
// search array a[] for char target, up to indexsize-1. // If found, return true. Otherwise return false.
bool find_char (char target, char a[], int size)
{ for (int i=0; i < size; i++) { if (a[i] == target) return true; } return false; } //Delete repeat characters from a[] and return // the new size in position_used. void delete_repeats(char a[], int& positions_used) { int new_size = 0; for (int i = 0; i < position_used; i++) { if (!find_char(a[i], a, new_size)) { a[new_size] = a[i]; new_size++; } } position_used = new_size; } 50 C:Dev-Cppch7_pp2.cpp `position_used' undeclared (firstuse this function) (Each undeclared identifier is reported only once for eachfunction it appears in.) 52 C:Dev-Cppch7_pp2.cpp name lookup of `i' changed for newISO `for' scoping 50 C:Dev-Cppch7_pp2.cpp using obsolete binding at`i'
Here is the program:
#include <iostream> //function prototypes void delete_repeats(char a[], int& size); bool find_char (char target, char a[], int size);
int main() {
using namespace std; char a[81] = "mary had a little lamb. its fleecewas white as snow."; int size = 53;//sample main character size53
cout << "Before: size = " << size<< " array = " << endl; for (int i=0; i<size; i++)//output beforesize { cout << a[i];//outputs allcharacters } cout << endl;
delete_repeats(a,size);//deletesrepeat
cout << "After: size = "<< size<< "array = " << endl; for (int i=0; i<size; i++)//output after newsize { cout << a[i];//output after removingextra characters, spaces } cout << endl; return 0; }
// search array a[] for char target, up to indexsize-1. // If found, return true. Otherwise return false.
bool find_char (char target, char a[], int size)
{ for (int i=0; i < size; i++) { if (a[i] == target) return true; } return false; } //Delete repeat characters from a[] and return // the new size in position_used. void delete_repeats(char a[], int& positions_used) { int new_size = 0; for (int i = 0; i < position_used; i++) { if (!find_char(a[i], a, new_size)) { a[new_size] = a[i]; new_size++; } } position_used = new_size; } #include <iostream> //function prototypes void delete_repeats(char a[], int& size); bool find_char (char target, char a[], int size);
int main() {
using namespace std; char a[81] = "mary had a little lamb. its fleecewas white as snow."; int size = 53;//sample main character size53
cout << "Before: size = " << size<< " array = " << endl; for (int i=0; i<size; i++)//output beforesize { cout << a[i];//outputs allcharacters } cout << endl;
delete_repeats(a,size);//deletesrepeat
cout << "After: size = "<< size<< "array = " << endl; for (int i=0; i<size; i++)//output after newsize { cout << a[i];//output after removingextra characters, spaces } cout << endl; return 0; }
// search array a[] for char target, up to indexsize-1. // If found, return true. Otherwise return false.
bool find_char (char target, char a[], int size)
{ for (int i=0; i < size; i++) { if (a[i] == target) return true; } return false; } //Delete repeat characters from a[] and return // the new size in position_used. void delete_repeats(char a[], int& positions_used) { int new_size = 0; for (int i = 0; i < position_used; i++) { if (!find_char(a[i], a, new_size)) { a[new_size] = a[i]; new_size++; } } position_used = new_size; }
Explanation / Answer
for (int i = 0; i < position_used; i++) // "s" ismissing in position_used and in position_used = new_size; // "s" is missing
-Hope this helps - I corrected and it compileds
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.