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

Viusal C++ help

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 18
Thread images: 3

File: Untitled.png (127KB, 1368x920px) Image search: [Google]
Untitled.png
127KB, 1368x920px
Hello. I'm trying to do my CP homework and I'm not managing too well. When I was in highschool, we used to do C++ in Codeblocks but now in college we do Visual Studio and it's pretty confusing to me. Could you tell me what I did wrong here? If not could you redirect me to another board?
>>
Post the compiler error.

Also: "%f %f %f" put spaces there
>>
Printf lacks print descriptor.

Its super shitty code but it should work.
>>
File: Untitled2.png (5KB, 602x286px) Image search: [Google]
Untitled2.png
5KB, 602x286px
>>57482970
No errors. It doesn't show me the average value.
>>
>>57483006
you forgot the variable descriptor in the last print line, it should be
printf("\nMedia aritmetica %f", m);
>>
>>57482990
How could I make it better giving the fact I know alost nothing about these weird operators? Could you give me a more "advanced" version?
>>
>>57483022
Oh wow it worked. Thanks a lot. How weird that i have to put %f even though i declared m as float
>>
>>57483043
you have to put the %f and stuff whenever you want to insert it variables into any print statement

like if you wanted to print out a character, you'd add %c in the quotes, then after quotes have the variables in the corresponding order

for example if you wanted to print out an int, char, and float in the same print statement you'd do
printf("%d %c %f", intVar, charVar, floatVar);


the %d and stuff just lets the printf statement know what it's expecting to put in that location
>>
>>57483067
Thanks. I'll have to use this stuff in another problem. Also why do i have to put "&" before the n variables in the example above.
>>
File: BerryEatingAnimals.jpg (190KB, 700x368px) Image search: [Google]
BerryEatingAnimals.jpg
190KB, 700x368px
>>57483067
You're a good guy.
I hope you have a great day.
>>
>conio.h
>cstdio
Why use those over iostream?
>>
>C++
>printf
>scanf
is ur professor fuking serious
>>
>>57483103
IDFK in highschool i used <iostream> cin, cout. This is one of the first homeworks and i think it's more an introductory one. I looked at some homeworks in advance and there is cin and cout
>>
>>57483092
& is the "address of" operator when it's in front of a variable name in a statement (in C++ it has other uses but that's what it is in this context)
Address of = Memory (RAM) location of the variable it's attached to

You need to use it in this context because scanf asks for a memory location to store user input in, so you input the memory location of n1 by saying &n1
>>
>>57483092
Having and & before a variable means the address of that variable. The scanf function takes the input in the specified format from your window buffer, in your case it's looking for 3 floats in the console widow, and then stores it in the memory location. The &n1, &n2, &n3 it telling the scanf function to store the 3 floats that were input into the addresses of n1 n2 and n3.
>>
>>57483130
>>57483137
Thank you
>>
>>57483092
Best thing you could do is have a read up on pointers.
When you pass a function some arguments in c it's given copies of the actual values. So you pass a reference to it so it can change the actual value in memory. The function is therefore given copies of the reference but of course the thing it's referring to is the same.

char in[5];

scanf("%s", in);

Will work as in is already a pointer (array).
Have a play around with & and * in c.
>>
>>57483176
Thanks
Thread posts: 18
Thread images: 3


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

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
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.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.