drk Posted April 13, 2012 Posted April 13, 2012 Hi guys! I started learning these days and I need know this: int a = 1, b = 2, c = 3; int result = ++a/a&&!b&&c||b--||-a+4*c>!!b; I know that it's needed to put two equal symbols to the system understand that it's to write "!!" and not use "!", but I can't understand this: c>!!b. Someone, help me please and sorry for can't explain good. EPT Team Server Development: 0% Learning C++ | C++ is amazing
karlis Posted April 13, 2012 Posted April 13, 2012 i think it'll output 2, cause 1st will be false, but b-- is still 2. [WIP]GTA IV style hud+custom blips + blip text + circular radar areas
drk Posted April 13, 2012 Author Posted April 13, 2012 Thanks for answering, but I wanna know only "c>!!b" EPT Team Server Development: 0% Learning C++ | C++ is amazing
karlis Posted April 13, 2012 Posted April 13, 2012 that's just a not not, resulting in false if b is false, or true if statement is any other value. im not experienced with C++, therefore i cant say would it cause errors, but boolean comparison to other size seems wrong to me. [WIP]GTA IV style hud+custom blips + blip text + circular radar areas
drk Posted April 13, 2012 Author Posted April 13, 2012 Okay. Thanks, now can someone explain me in this code: void main() { int i, j, k; printf ( "\n" ); for ( k = 0; k <= 1; k++ ) { printf ( "\n" ); for ( i = 1; i < 5; i++ ) printf ( "Tabuada do %3d ", i + 4 * k + 1 ); printf ( "\n" ); for ( i = 1; i <= 9; i++ ) { for ( j = 2 + 4 * k; j <= 5 + 4 * k; j++ ) printf ( "%3d x%3d = %3d ", j, i, j * i ); printf ( "\n" ); } } } Why just in 2 for loops it's needed keys { } ? EPT Team Server Development: 0% Learning C++ | C++ is amazing
Kenix Posted April 13, 2012 Posted April 13, 2012 (edited) It's optional use { } in for loop. #include <iostream> int main( ) { for ( int i = 0; i < 5; i++ ) printf( "%d \n", i ); return 0; } Output: 0 1 2 3 4 Also #include <iostream> int main() { int i = 10; if ( i ) printf( "%d \n", i ); return 0; } Output: 10 You can test it here: http://codepad.org/ Also you need better read documentation about c++ Edited April 13, 2012 by Guest http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
drk Posted April 13, 2012 Author Posted April 13, 2012 k Thanks, I understand now. EPT Team Server Development: 0% Learning C++ | C++ is amazing
drk Posted April 13, 2012 Author Posted April 13, 2012 It's optional use { } in for loop. #include <iostream> int main( ) { for ( int i = 0; i < 5; i++ ) printf( "%d \n", i ); return 0; } Output: 0 1 2 3 4 Also #include <iostream> int main() { int i = 10; if ( i ) printf( "%d \n", i ); return 0; } Output: 10 You can test it here: http://codepad.org/ Also you need better read documentation about c++ Also you need better read documentation about c++ I'm already learning C++ from a book I bought and It has much exercises and these things but don't explain somethings. EPT Team Server Development: 0% Learning C++ | C++ is amazing
drk Posted April 14, 2012 Author Posted April 14, 2012 I don't know if I must create a new topic for this, so here we go: #include "stdafx.h" #include <Windows.h> #include <stdint.h> int main() { int nPrimo; int bPrimo = 0; printf ( "Type a number: " ); scanf_s ( "%d", &nPrimo ); for ( int i = 2; i <= nPrimo; i++ ) { if ( nPrimo%i != 0 ) { bPrimo = 1; } if ( bPrimo == 0 ) { MessageBox ( NULL, L"The number is prime!", L"Information", MB_ICONQUESTION ); return 0; } else { MessageBox ( NULL, L"The number is not prime!", L"Information", MB_ICONQUESTION ); return 1; } } } I made this ( classes exercise ), It works now, but if number is 3 it says number is not prime lol I don't know why, can someone help? I can't understand this shitty prime numbers EPT Team Server Development: 0% Learning C++ | C++ is amazing
karlis Posted April 14, 2012 Posted April 14, 2012 it fist checks 2, and outputs what happened to 2, not whole loop. [WIP]GTA IV style hud+custom blips + blip text + circular radar areas
drk Posted April 14, 2012 Author Posted April 14, 2012 I know, but anyway 3 / 2 = 1,5, not 1. EPT Team Server Development: 0% Learning C++ | C++ is amazing
karlis Posted April 14, 2012 Posted April 14, 2012 it first checks 2 with 3, and 3%2 = 1 therefore not 0, then it returns without checking other values. [WIP]GTA IV style hud+custom blips + blip text + circular radar areas
drk Posted April 14, 2012 Author Posted April 14, 2012 No. 3 % 2 returns 0 lol 3,0 | 2 1 0 1,5 0 Rest -> 0 EPT Team Server Development: 0% Learning C++ | C++ is amazing
karlis Posted April 14, 2012 Posted April 14, 2012 (edited) 3/2 = 1 and remainder 1 Edited April 14, 2012 by Guest [WIP]GTA IV style hud+custom blips + blip text + circular radar areas
drk Posted April 14, 2012 Author Posted April 14, 2012 3/2 = 2 and remainder 1 I can't understand how can this be 1 if division 3 / 2 returns result 1,5 Edit: Oh, awesome! I understand now why is that returning 1. Thanks, I solved the problem. EPT Team Server Development: 0% Learning C++ | C++ is amazing
karlis Posted April 14, 2012 Posted April 14, 2012 3/2 = 1, remainder 1 ** [WIP]GTA IV style hud+custom blips + blip text + circular radar areas
drk Posted April 14, 2012 Author Posted April 14, 2012 Thanks for helping. EPT Team Server Development: 0% Learning C++ | C++ is amazing
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now