[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]

New to c++, really need some input here. How's this look?

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: 13
Thread images: 2

File: CPlusPlus.jpg (36KB, 433x455px) Image search: [Google]
CPlusPlus.jpg
36KB, 433x455px
New to c++, really need some input here.
How's this look? It works and I feel amazing for doing something this basic. Did I fuck anything up?

#include <iostream>

int main(){
int a = 0;
if (a > 20){
std::cout << "So a > 20?";
}
else{
std::cout << " Fuck Its wrong";
}
return 0;
}
>>
>>56068972
two things, it's a short snippet so it's hard to judge anything from it - but keep using the full namespace (std::) as that's good practice.

second, I recommend using code tags on /g/:

>>
>>56068972
Gr8 b8 m8 I r8 8/8, no h8 or deb8
>>
>>56068994
Oops,

[ code]

[ /code]

Minus the spaces
>>
int main(int argc, char *argv[]) //command line arguments
{
int a = 0;
if (a > 20){
std::cout << "So a > 20?" << std::endl; // std::endl to break the line
}
else{
std::cout << " Fuck Its wrong" << std::endl;
}
return 0;
}
>>
File: cppaccident.jpg (89KB, 513x437px) Image search: [Google]
cppaccident.jpg
89KB, 513x437px
what's wrong with this code:


int choice = 0;
do{
cin >> choice;
}while(choice != 1 ||
choice != 2 ||
choice != 3);


if there is a menu with only 3 options
>>
>>56068972
You should create something that let the user input the value of a...
eg.: std::cout << "Input the value of a:";
std::cin >> a;

if(a > 20) etc etc
>>
>>56069033
The menu is not inside the loop
>>
>>56068972
Write in C
>>
Why exactly Is It that If I enter an age greater than 50 I get a result that Is all of my possible outputs? IE: I enter 70, and get my two if statements, and my else statement. I've tried to use else if but It doesn't seem to work.

[ code]
#include <iostream>
using namespace std; // Important part of the program
int main(){
int age; // need var

cout << " Please enter your age: ";
cin >> age;
if ( age > 30){
cout << " Still considered young";
}
if (age > 50){
cout << " entering middle age :/ ";
}
else(age < 30);{
cout << " I guess you're a child'";

}
return 0;
cin.get();


}
[ /code]
>>
>>56069206
I've heard It's good for beginners, but I've hopped around too much learning while loops In five languages really doesn't help you understand programming. I settled with c++ and don't intend to switch for the purpose of actually learning the damn thing.
>>
>>56069210
this is obviously your homework, but I'll help since you're so helplessly bad at this.

IF statements, every single one of them applies if the conditions are met.

What you need to do if you want to restrict something to not happen is ELSE-IF.

You tried that and failed, the problem was your ordering.
You have to choose the order of your tests.
You want the oldest one to apply, so you do
IF (age > 50), ELSE IF (age > 30), ELSE child thing.
That's because if someone is 60, you want to hit the 50+, not the 30-50.
You can order this kind of test from highest-to-lowest or from lowest-to-highest.

Lowest to highest does exact same thing in reverse
if (age < 30) {young stuff}
else if (age < 50) {middle stuff}
else { old stuff }

30, 50, 0-29 is not in ANY order, which is why it failed so badly.
>>
>>56068972
How old are you OP?

if you are above 25 you are fucked up
if you are under 15, and put some effort on this and read some good books you could make it...
Thread posts: 13
Thread images: 2


[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.