New to programming.
Is there an easier way to do this?
tips/suggestions?
>>53647567
Learn how the language works and what constructs it offers first.
There are 3 VERY BASIC things which you can use here to make your life a lot easier, which you'll have to figure out.
learn the basics and use fucking for-loops
>>53647567
>>53647653
Also, there's already a thread for this shit called daily programming thread.
Lurk moar.
also quit using arrays
There's no mod in C?
and i thought my code is horrible
>>53647567#include <iostream>
using namespace std;
int main(void)
{
int i;
cout << "Even numbers to twenty are ";
for (i = 0; i <= 20; i++)
if (i % 2 == 0)
cout << i << " ";
cout << endl;
cout << "Odd numbers to twenty are ";
for (i = 0; i <= 20; i++)
if (i % 2 == 1)
cout << i << " ";
cout << endl;
return 0;
}
[\code]
>>53647567
Haven't used c++ in some time, but you probably want to do something like this#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> evens;
vector<int> odds;
for (int i = 0; i <= 20; i++)
{
if (i % 2 == 0)
{
evens.push_back(i);
}
else
{
odds.push_back(i);
}
}
cout << "Evens:" << endl;
for (int n : evens)
{
cout << n << " ";
}
cout << endl;
cout << "Odds:" << endl;
for (int n : odds)
{
cout << n << " ";
}
return 0;
}
>>53647567
functions
yea you should be using pythonfrom faggot import OP
print range(0,20,2)
print range(1,20,2)
>>53647567
When I see shit like this I know my job is pretty safe for at least another generation...
>>53649828
Pretty much the same in racket:
(display (range 0 20 2))
(display (range 1 20 2))
Or:
(display (filter even? (range 20)))
(display (filter odd? (range 20)))
>he fell for the C as a first language meme
You poor bastard
>>53650903
that's cpp
>>53650903
It’s C++, but I agree with you.
Though if they succeed learning and mastering this language, this could be a pretty huge advantage for them later
Not OP. I am starting a new job on the 4th of next month programming in BCPL... The interviewers joked about it calling it 'Before C Programming Language', invented in 1966.
Should be fun I guess and I can't find much about it at all. I feel like continuing with C/C++ will be a good step for me now, moving from a primarily PHP background.