Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions exercises/verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,36 @@ The number 3 is [not] present in the array.
#include <iostream>
using namespace std;

bool isPresent(int* Arr, const size_t& size, const int& n);
void printOutput(bool present);

bool isPresent(int* Arr, const size_t& size, const int& n){
for(size_t i = 0; i < size ; i++){
if(Arr[i] == n){
return true;// FOUND!!
}
}
return false;
}

void printOutput(bool present){
cout << "The number is ";
if(!present){ //not present
cout << "not ";
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not bad 👍

cout << "present in the array." << endl;
}

int main()
{
// placeholder
int N[10] = {3, 4, 5, 1, 2, 3, 4, 9, 13, 0};
int N[] = {3, 4, 5, 1, 2, 3, 4, 9, 13, 0};
size_t arrSize = 10;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dimensione t mi è sempre sembrato poco chiaro e significativo come "nome" del tipo
di fatto è un unsigned long, non so quanto convenga usare size_t rispetto ad altri tipi

int numInput;

cout << "Insert number: " << endl;
cin >> numInput;

printOutput( isPresent( N , arrSize , numInput) );

return 0;
}