Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is C++ code I am having a problem to running code I am getting an error so I need help to run the code.

This is C++ code I am having a problem to running code I am getting an error so I need help to run the code.

#include #include using namespace std;

void CheckValid(vector numberList) { int size = numberList.size(); cout << "List : "; for (int i = 0; i < size; ++i) { cout << numberList[i] << " "; } cout << " "; // checking size of the list is ==9 if (size != 9) { cout << "INVALID : lenght of list is not 9 "; return;

}

//checking for rang and duplicates int arr[10] = { 0 }; for (int i = 0; i < size; ++i) { // range check if(numberList[i] > 9 || numberList[i] < 1){ cout << "INVALID : " << numberList[i] << " Exist in list with is out of range "; return; }else{ // dupclicate check arr[numberList[i]]++; if (arr[numberList[i]] == 2) { cout << "INVALID :" << numberList[i] << " Exist more than once in the list "; return;

}

} } //if all is correct then it is valid cout << "List is VALID "; return;

}

//testing + main function int main() { vector numberList{ 1,2,3,4,5,6,7,8,9 }; checkValid(numberList); vector numberList1{ 0,2,3,4,5,6,7,8,9 }; checkValid(numberList1); vector numberList2{ 1, 2, 2, 4, 5, 6, 7, 8, 9 }; checkValid(numberList2); vector numberList3{ 1,2,2,4,5,6,7 }; checkValid(numberList3); vector numberList4{ 1,2,2,4,5,6,7,8,9,10 }; checkValid(numberList4); vector numberList5{ 1,2,3,4,5,6,7 }; checkValid(numberList5);

return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

PostgreSQL Up And Running A Practical Guide To The Advanced Open Source Database

Authors: Regina Obe, Leo Hsu

3rd Edition

1491963417, 978-1491963418

More Books

Students also viewed these Databases questions