It does some really cool stuff when datapts is zero.
3. Evaluate !(1 && !(0 || 1)).
A. True
I don't understand why this is true......can someone please break it down and explain it to me? thanks
1 = true,
0 = false
==> !(true && !(false || true))
==> !(true && !(true))
==> !(true && false)
==> !(false)
==> true
!(1 && !(0 || 1)).
Remimber your order of operations.
( 0 || 1 ) = 1
! (1 && !(1))
! (1 && 0)
! (0)
1
Oh ok ya so even though "that OR will be evaluated after AND. " you have to still follow order of operations 1st! ok that makes sense. thank you!
(0||1) = true
!(0||1) =false
1 && 0 = false
! ( 1 && 0) = true
Ok still going over the C++ tutorial on lesson 3
Code:#include <iostream>
using namespace std; // So the program can see cout and endl
int main() { // The loop goes while x < 10, and x increases by one every loop
for ( int x = 0; x < 10; x++ )
{ // Keep in mind that the loop condition checks
// the conditional statement before it loops again.
// consequently, when x equals 10 the loop breaks.
// x is updated before the condition is checked.
cout<< x <<endl; }
cin.get();
}
What does the cin.get(); do? It doesn't explain it as far as I can see and when I used it in code blocks I didn't notice anything different then when I didn't use it.
what does str[i] = str[i] - 'a' + 'A'; mean in the code below
thanks I have an exam at 1pm so any help would be great... I have to write 2 programs with prototypes in a hour so ya thanks.Code:#include <iostream>
using namespace std;
int main()
{
cout << "Enter a character string: ";
char str[20];
cin >> str;
for (int i=0; str[i]; i++)
{
if ((str[i] >= 'a')&& (str[i] <= 'z'))
str[i] = str[i] - 'a' + 'A';
else
{
if ((str[i] >= 'A')&& (str[i] <= 'Z'))
str[i] = str[i] + 'a' - 'A';
}
}
cout << str << endl;
return 0;
}
Characters are basically integers with limited ranges (0-255 for an 8-bit unsigned char as an example). You can therefore perform arithmetic on char data types of the sort you are seeing here. Imaging for a moment that str[i] contains the letter 'b'. Subtracting 'a' from 'b' results in a difference of 1. If we then add 'A' and 1 together what do you think the result is?
Chars are stored as single bytes. A single 8-bit byte has 256 possibilities; ie, a numerical value from 0-255 (unsigned) or -128 to 127 signed. These correspond to the ASCII table:
Ascii Table - ASCII character codes and html, octal, hex and decimal chart conversion
So if you subtract 'a' (97) from a lowercase ASCII letter and then add 'A' (65) to it, it will be capitalized.