I don't know what i'm doing wrong. I did everything perfectly and it's showing massive amounts of syntax errors according to my professor. I have checked over and over and see no errors. I have had friends check and see no problems with it. The only problem I see is when compiling. Anybody know whats up with this?
That's a pretty big problem if your code can't be compiled, isn't it? Paying attention to the error messages at compilation is the first step towards self sufficiency.
If you ever find yourself uttering the words "I did everything perfectly" followed by "the only problem I see is when compiling" reconsider the former.
1 : int foundIndex = linearSearch(arr, Size, SearchNum);
change arr[] to arr
2 : int linearSearch(int arr[], int Size, int SearchNum)
change linearsearch to linearSearch
try to understand the error messages of the compiler give you.
Bonus :
1 : c++ is not c89, you don't need to declare every parameters before the function, please study what is "lazy initialization".
2 : please study stl, it is an essential part of c++.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <algorithm>
#include <array>
#include <iostream>
#include <iterator>
int main()
{
std::array<int, 5> arr{{1,2,3,4,5}};
//or you could use int arr[] = {1,2,3,4,5};
auto it = std::find(std::begin(arr), std::end(arr), 3);
if(it != std::end(arr)){
//you could use std::distance to find the distance too, it is more generic
std::cout<<*it<<" found at index "<<(std::end(arr) - it)<<std::endl;
}
}
I wholly agree with you there LB. I've never actually took a college class, but the few solutions I've given to others problems were turned down because of picky profs.