[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
C++ Where do I start with this? Can someone link me to a viable
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 76
Thread images: 4
File: aa.png (84 KB, 847x661) Image search: [Google]
aa.png
84 KB, 847x661
C++

Where do I start with this?

Can someone link me to a viable site to learn what ShowOptions, EnterOptions, and PrintSeries does? I'm trying to figure out how they work, but I can't find anywhere that explains the code.
>>
>>51514009
This isn't bad: http://www.cplusplus.com/doc/tutorial/

It doesn't completely follow modern best practices but it will get you going.

>ShowOptions, EnterOptions, and PrintSeries
These are functions you are supposed to write, not existing ones.
>>
Jesus christ, what a retarded assignment
>>
>I can't find anywhere that explains the code
Read the assignment. You write the code yourself, dumbass. Maybe you should learn English first :^)
>>
>>51514056

fucking tell me about it lol
>>
void printSeries(int n)
{
for (int i = n; i <= 1000 - 1000%n; i += n)
{
std::cout << i << ' ';
}
}
>>
>>51514174
As awfully convoluted as expected from /g/
>>
>>51514174

void PrintNumberBetween0and9()
{
cout << "\n\n";
int k;
for (k = 0; k <= 9; k++)
cout << " " << k;
}

like this?
>>
>>51514009
>can't find anywhere that explains the code
coz you're supposed to write and implement it yourself. god. do you even know what you're doing?
>>
This assignment is so easy, make a switch statement as a function that takes 1 integer argument, call a function that takes in an int in your main, make another function that takes an argument from your switch then does the calculate and another one that prints. It you honestly can't figure this out idk what to tell you.
>>
>>51514250

how do you clean it up? Removing std::cout and placing cout << " " << i; ?
>>
>>51514276
Void PrintSeries (int n)
{
for (int i; i <= 1000; i++)
{
if (i % n == 0)
{
cout << i << " ";
}
}
}
>>
#include <iostream>

int enterOption();
void printSeries(int n = 1);
void showOptions();

int main()
{
return 0;
}

int enterOption()
{
int n;

do {
std::cin >> n;
} while (n < 0 || n > 9);

return n;
}

void printSeries(int n)
{
for (int i = n; i <= 1000 - 1000%n; i += n)
{
std::cout << i << ' ';
}
}

void showOptions()
{

}


Here, OP. I did some of it for you. Try to figure out the showOptions function and how to call your functions from main.
>>
>>51514465
The assignment is already needlessly complicated by requiring you to use functions for what could be accomplised with a couple of loops, stop having a separate function for fucking everything

Also, unless it's required by your teacher, stop using shitty visual c++ and use standard c++ instead
>>
>>51514632

it's required. she even demanded I send .zip files instead of .rar files which resulted in two 0's for me.

this is confusing the shit out of me to go it with functions instead of loops. idk how to do either but logically, loops make 100x more sense than this.
>>
>>51514465
Is the bit you posted in the OP supposed to be part of a latger assignement? otherwise that pastebin has lots of unnecessary and redundant shit
>>
>>51514714

It was part of what I was reading and I added it in to think things through, didn't help at all.
>>
>>51514775
Just delete it and start all over again

And don't put random functions for Christ's sake
>>
>>51514811

http://pastebin.com/9G9vjheW

mother of god. I don't know how to write a function that calls for what each option is suppose to display AND display it while giving the option to select from a list.

I understand that it's the ShowOptions to show to information for them to select from. Does that mean that I'm making a function to call from for EACH option??

If so, each option gets a function and then I make a function to sort 0 through 9 in order to show which option to display.

Then I would need a function per option to calculate what each function would perform.

So Program starts > ShowOptions > EnterOptions > function to perform math > PrintSeries > ShowOptions.

But how do I call a function to print for the user to read and then enter an option? Those are two separate functions.
>>
>>51514678
>using .rar
i would given you 0's too
>>
>>51515029
>Program starts > ShowOptions > EnterOptions > function to perform math > PrintSeries > ShowOptions.

Pretty much, but your printSeries is the function that "performs math" and you don't need to show the options again at the end. So your main will look something like this.

int main()
{
showOptions();

int option = enterOption();

printSeries(option);

return 0;
}
>>
>>51515233

but if it's suppose to perform a different operation per input, how do i fit that into a singular printSeries function?
>>
http://pastebin.com/094xcQkX
There, did most of the work for you (there is a mistake in the declaration of ShowOptions that I'm too lazy to go back and fix, tho)

>>51515591
The PrintSeries posted earlier does all the work, if you don't know how the modulo operator works you shoukd seriously consider going back to the basics and/or kill yourself
>>
>>51516132
>>51514461
Pretty good, but please don't do people's homework on here
>>
>>51516865

but I will never understand this on my own

I worked it out but my VS won't let me use #include "stdafx.h", gives me a failure every time I try to debug and doesn't open the code.

Anyone know how to fix it?
>>
>>51516972
Stop using visual studio
>>
>>51516972
You know it will help if you can paste the error messages here...
>>
File: err.png (8 KB, 1245x97) Image search: [Google]
err.png
8 KB, 1245x97
>>51517023
it's required for the class or i wouldn't use that shit

>>51517041
>>
>>51517070
http://stackoverflow.com/a/7261771
>>
>>51514461
>>51515233
Functions are named incorrectly. I'll give you 1 out 10, and that's the best I can do.
>>
>>51517023

I'll second this. And in fact, I'll offer an alternative.
http://tdm-gcc.tdragon.net/
>>
>>51517070
I feel sorry for whatever shithole you are studying at and the shit degree you are gonna get
>>
>>51514174
> not just putting your condition in the for loop
>>
>>51517070

>it's required for the class
Does your professor require you to turn in Visual Studio project files? Or just source code? If the latter, build with gcc, turn in your source, and just make sure that what you're using doesn't use C++11 and C++14 features that aren't available in Visual Studio.
>>
>>51517106
>not even a screnshot

Welp. It's shit then.

After you learn to fight off its quirks, VS is godly. Though Qt Creator has become very good lately, also. But its debugging mode is still too sluggish and too buggy.

>>51517070
Remove stdafx
>>
>>51514678
>this is confusing the shit out of me to go it with functions instead of loops. idk how to do either but logically, loops make 100x more sense than this.

Can anyone really be this retarded?

Dumbfuck, you aren't using functions INSTEAD of loops. Functions are just a way to structure your code.
>>
>>51517135

both. also wants a screenie of the output window but hey, mine was fucked lol.
>>
>>51517133
what
>>
>>51517139
Someone does not know about recursion. Tsk-tsk.
>>
>>51517070
did you delete or alter any files generated by VS?
>>
>>51517161

no, it's a mounted ISO so that might be my problem. i downloaded a legit copy from MS and had the same issue, so i went to the seas in search of treasure and had the same issue.

i will try the link that anon posted, though.
>>
>>51517137

TDM is literally just an easy to install distribution of MinGW-w64, which in turn is just GCC and all of the GNU build utilities for Windows. Why would they offer screenshots of a program that is literally run in the console?
>>
File: IMG_7911.jpg (115 KB, 1280x853) Image search: [Google]
IMG_7911.jpg
115 KB, 1280x853
>>51517139

got a wall paper for you anon
>>
>>51517183
I'm not asking why they are not offering screenshots.

I'm just making a conclusion.

No screenshots, means it's shit.

It's not even an IDE.
>>
>>51517070

Either put #include "StdAfx.h" at the top of your source file, or go into settings for the source file and turn off precompiled headers.
>>
>>51517159

Hey, nobody mentioned stack abuse.

>>51517190

No idea what that means.
>>
Pay attention in class fag or go ressit hw help
>>
>>51517220
Someone does not know about tail call optimization. Tsk-tsk-tsk.
>>
>>51517243

You mean turning recursion into a loop?

We gonna do another round of this?
>>
>>51517220

it's a mountain of salt, sorry didn't change file name
>>
>>51517270
You are using functions in your source code. You are not using loops in your source code. Hope this helps you understand the problem well enough. Take care!
>>
>>51517318

i am op, that is not me.
>>
>>51517336
I know it's not you. We are not talking about you. I am trying to explain difference between loops and functions to a person who is about as clueless about programs as you.
>>
>>51517200

>It's not even an IDE.
That's the fucking point.
>>
>>51517352
Recommending not using IDE to a newbie is not very nice.
>>
>>51517318
>>51517347

What the fuck are you blathering about?
>>
>>51517347

i am clueless but just to clarify: a loop repeats until it hits a snag and a function is a separate program that can be called upon any time within the code, right?
>>
>>51517416

Sort of.

Dunno wtf "a snag" is.
>>
>>51517415
About how you don't know very well about recursion, which allowed you to make statements as silly as in >>51517270 >>51517220 >>51517139.
>>
>>51517437

put it in to code so we can all learn wtf you two are saying
>>
>>51517504
The code has already been written for you, and there has been multiple suggestions how to fight off stdafx issue, you lazy ass.
>>
>>51517437

Fuck off, you retard.

I'm trying to talk to a newb here, not plumb the depths of recursion.

Jesus fucking Christ, I can't stand assholes like you. You alpha-nerd wannabe loser piece of shit.

Take your tail recursion and shove it up your pedantic, autistic ass.
>>
>>51517551
IMG_7911.jpg
>>
>>51517521

no, retard. i already finished my assignment, i want to know what these two are fighting about. they're saying there is a difference in the thing they disagree on, so i wanna see what they mean in code.
>>
File: 1444549760041.gif (988 KB, 500x400) Image search: [Google]
1444549760041.gif
988 KB, 500x400
>>51517565

i like you.
>>
>>51517649
Just for you:


Code using loops:
int main(){
for(int i=10;i>0;i--){
printf("%d\n",i);
}

return 0;
}


Code using function calls:
void r(int value){
if(value<=0) return;

printf("%d\n",value);
r(value-1);
}

int main(int argc, char *argv[]){
r(10);

return 0;
}


They do the same thing differently.
>>
>>51517365

IDE's convolute and abstract away the build process from the beginner. Let them learn how the fuck the tools they use work first, then let them pick an IDE if they find it more productive.
>>
>>51518331
Disagree. Let them press a button to get their program to work instead of having to write text in command line or even worse write code for makefile.
>>
>>51518344

And then they have to start writing nontrivial programs that need libraries, or they need to use a specific standard of C, or they need some sort of optimization flag, or need to make a shared library... any deviation from what they are used to, and the fact that they don't know how to use the compiler, or even what the hell a linker is, will cause them nothing but trouble.

Buidling programs, once you get beyond fizzbuzzing, often involves complex build environments, and it fucking helps to be able to understand them instead of working with some preset that doesn't work with your specific edge case.

Also, makefiles aren't that fucking hard.
>>
>>51518456
>And then they have to start writing nontrivial programs that need libraries, or they need to use a specific standard of C, or they need some sort of optimization flag, or need to make a shared library... any deviation from what they are used to, and the fact that they don't know how to use the compiler, or even what the hell a linker is, will cause them nothing but trouble.
Solving those problems involves only following instructions... for both IDE and command-line approach. Not much difference there.
>>
>>51514420
Congratulations, your code will crash.
>>
>>51518536
?
>>
>>51518610
>int i;
>>
>>51518617
I don't get it
>>
>>51518617
Oh wait I see it, nevermind

It was just a quick throwaway function for the op typed on my phone
>>
>>51518665
Your code is trash. For n=9 you will have 9 times more iterations that code posted in >>51514174.
Thread replies: 76
Thread images: 4

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.