Anonymous
حسام
Can you provide your code? At least of the function that works incorrectly
#include <iostream> using namespace std; void inputArray(int array1[5], int array2[5]); void maxArray(int array1[5], int array2[5], int arraym[5]); void PrintArray(int array[]); int main() { int a[5]; int b[5]; int m[5]; inputArray(a, b); maxArray(a, b, m); PrintArray(m); } void inputArray(int array1[5], int array2[5]) { int i; cout << "enter values for the first array: \n"; for (i = 0; i < 5; i++) cin >> array1[i]; cout << "enter values for the second array: \n"; for (i = 0; i < 5; i++) cin >> array2[i]; }; void maxArray(int array1[5], int array2[5], int arraym[5]) { int i; int max = 0; for (i = 0; i < 5; i++) { if (arraym1[i] > array2[2]) max = arraym[i]; } }; void PrintArray(int array[]) { cout << "the values of the array are: \n"; for (int i = 0; i < 5; i++) cout << array[i] << " "; }
حسام
I would've earlier but unfortunately you can't share photos in here
Pavel
I would've earlier but unfortunately you can't share photos in here
Fortunately, because now I can copy it to an online compiler to investigate
Pavel
did you want to do something like arraym[i] = std::max(array1[i], array2[i]);?
حسام
if (array1[i] > array2[2]) { max = arraym[i]; } What do you expect this code to do? You set max to a value from arraym[i], but the values of your arraym are not initialized
I’m a bit sketchy on arrays but the purpose I think is to compare the values of array1 and array2 which I initialize in the first function, if the value of array1 is less than the one in array2 it skips it
Pavel
I’m a bit sketchy on arrays but the purpose I think is to compare the values of array1 and array2 which I initialize in the first function, if the value of array1 is less than the one in array2 it skips it
yes, but you assign an uninitialized value to max and you never use this max. and even if you used it, not sure what could it give I mean, can you tell, what should be a result of your maxArray function? should it be an int of the max element from two arrays? or should it be an array that contains max elements on all the positions from these two arrays?
Pavel
Because now it feels like you tried to do both half way
حسام
My only reference for this problem is the max for a single array which I can do, the point here is an array that contains the max elements of the two arrays entered
حسام
But I don’t know what to replace the variable max with for it to store the new array in somewhere to print it
Pavel
My only reference for this problem is the max for a single array which I can do, the point here is an array that contains the max elements of the two arrays entered
void maxArray(int array1[5], int array2[5], int arraym[5]) { for (int i = 0; i < 5; i++) { arraym[i] = std::max(array1[i], array2[i]); } } So, something like this you mean?
حسام
Yes exactly, but now the problem becomes how do I compare the elements of a1 and a2 to determine which one is the biggest
Pavel
Yes exactly, but now the problem becomes how do I compare the elements of a1 and a2 to determine which one is the biggest
if (array1[i] > array2[i]) { cout << "1 is bigger"; } else if (array2[i] > array1[i]) { cout << "2 is bigger"; } else { cout << "equal"; }
حسام
Man what a legend, I’m new to c++ so I don’t know all the functions correctly but the std::max worked like a charm
حسام
Thank you mr. Pavel
Pavel
Man what a legend, I’m new to c++ so I don’t know all the functions correctly but the std::max worked like a charm
good, do you want suggestions/advises about how you can improve the code you've sent?
Pavel
Can I do it without the function max?
yes, with the code above, something like this if (array1[i] > array2[i]) { arraym[i] = array1[i]; } else if (array2[i] > array1[i]) { arraym[i] = array2[i]; }
حسام
Wow
حسام
Where Does knowledge like this come from
حسام
I’ve been stuck for about 2 hours trying to solve it
.
How to make array elements equal given costs of each element in minimum cost?
.
Input Arr 3 1 2 Cost 1000 10 100 Output Minimum Cost 120
.
Help
Wijdan
Can you tell me what's wrong with this written code?
Wijdan
#include <iostream> #include <fstream> #include <string> using namespace std; void openFiles (ifstream& data, ofstream& output); void printResults (ofstream& outData, string& fName, string& lName, string& mName ); void findNames (string&line, string& fName, string& lName, string& mName); bool middleName (string& line); int name() { ifstream readbata; ofstream writeData; string line; string first_name; string last_name; string middle_name; openFiles(readbata, writeData); while (getline(readbata,line)) { findNames (line, first_name, last_name, middle_name); printResults(writeData, first_name, last_name, middle_name); } readbata.close(); writeData.close(); return 0; } bool middleName(string&line) { int count_spaces=0; for (int i=0; i<line.length(); i++) { if (line[i]==' ') count_spaces++; } if (count_spaces==1) return false; else return true; } void openFiles(ifstream& data,ofstream& output) { data.open("infile.txt"); output.open("outfile.txt"); if (!data) { cerr<<"cannot open input file."; } } void printResults (ofstream& outData, string& fName, string& lName, string& mName) { outData<<fName<<" "<<mName<<" "<<lName<<endl; } void findNames (string&line, string& fName, string& lName, string& mName) { fName.clear(); lName.clear(); mName.clear(); int start,end; if(middleName(line)) { start= 0; end = line.find(','); lName=line.substr(start,end-start); start=end+1; end=line.find(' ',start+1); fName=line.substr(start+1,end-start-2); start=end+1; end=line.find('\0'); mName=line.substr(start,end-start); }else{ start=0; end=line.find(','); lName=line.substr(start,end-start); start=end+1; end=line.find('\0'); mName=line.substr(start+1,end-start-2); } }
Ибраги́м
Money solves everything
Tried bribing death ?
Anonymous
Am a beginner with no clue in programming anyone willing to guide me from scratch dm me please i would like to learn
Janko Ⓥ
Am a beginner with no clue in programming anyone willing to guide me from scratch dm me please i would like to learn
You have great documentation and tutorials, a lot of people here learn on their own and so can you.
Janko Ⓥ
I would help you with software setup though
Janko Ⓥ
Has anyone here read "C Primer Plus"?
Anonymous
LoL
Anonymous
Janko Ⓥ
Tcl
Anonymous
Sure
i mean that's what i did dont know if it's recommended lol
Anonymous
python then C/Cpp
Anonymous
Tcl
huh
Janko Ⓥ
huh
Chad language. Has great interaction with C. The author also wrote Tk, of which the Python binding is called Tkinter
Anonymous
i mean that's what i did dont know if it's recommended lol
Am down with anything... Am a quick learner and can juggle both at a go
Anonymous
Anonymous
Chad language. Has great interaction with C. The author also wrote Tk, of which the Python binding is called Tkinter
i mean if ya wanna start to get around programming like the math and logic stuff python should be great?
Anonymous
Am down with anything... Am a quick learner and can juggle both at a go
python basics and questions then head to C/Cpp ig?
Anonymous
python basics and questions then head to C/Cpp ig?
Can you guide me then like be a tutor
Anonymous
Can you guide me then like be a tutor
i mean if ya facing trouble then feel free to pm anytime geeksforgeeks and other sites are superb to learn from plus youtube has some awesome tutorials
Anonymous
What's simple?
assembly (jk)
Anonymous
Anonymous
lmfao
Hamid
What's simple?
tbh nothing is simple if you wanna dive into it, but there are some programming languages that looks simplres and more understandable than others like python, javascript, nim, ... i suggest to start and then switch on other languages if you want
Anonymous
As would Tcl.
yeeee ig havent tried it sorry 😅
Anonymous
Hello, who knows piracy?
Anonymous
Hello, who knows piracy?
ummm what do u even wanna do with it
Anonymous
ummm what do u even wanna do with it
I want to get the data that was leaked from Facebook
Anonymous
bruhhh whyyy even
I want to see it
Anonymous
lol
Ramin
Tried bribing death ?
Heard about surgery and stuff?
Ибраги́м
Heard about surgery and stuff?
Death is like a goal in football, u never defend goals. U don't prevent DEATH.
Ибраги́м
Now think about that like three times or more
Ибраги́м
Same way you'd do for a cluster of template metaprogramming
Abhishek
Hi Guy's
Bumpy
Hello eve
Bumpy
i have a question about 2D vectors in CPP
Bumpy
void Board::resizeBoard(uint row , uint column,Direction direction) { if (direction == Horizontal) { setRow() = max(row ,getRow()); setColumn() = max (column,getColumn()); this->board.resize(getRow(),vector<char>()); this->board[row - 1].resize(column,'_'); } }
Bumpy
I have an assignment and the require is to build Dynnamic Board
Bumpy
if i want to insert a word in [0,0] and after that in [3,5]
Bumpy
i need to initialize all the "rows" between them?