Comp Sci Difference between some if statements C++

  • Thread starter Thread starter asz304
  • Start date Start date
  • Tags Tags
    C++ Difference
AI Thread Summary
The first if statement checks if 'a' is non-zero, while the second checks if 'a' is negative, leading to different execution conditions. Two-dimensional arrays are useful for representing data in a grid format, such as graphics or tables, allowing for organized data management. To change the brightness of an image in C++, a graphics library is necessary to handle display functions and modifications. The formula provided for brightness adjustment may be incorrect, as it suggests averaging color values, which could lead to unexpected results. Using pass by reference is advisable to ensure changes persist outside the function scope.
asz304
Messages
107
Reaction score
0
Say for example
Code:
 int a = 0; 
if ( a ){
...
}


int a = 0;
if ( a < 0 ){
...
}

What's different with the first if statement? or do they have the same meaning?

Thanks

EDIT: What is the use of two-dimensional arrays? I see it mostly in file input output stream stuff.

And how do I change the brightness of a picture using c++ using this formula:

R2 = G2 = B2 = (R1 + G1 + B1)/3

Do I need to use pass by reference?
 
Last edited:
Physics news on Phys.org
In this case nothing, the loop doesn't execute for a=0

The first one will execute for any value of 'a' other than 0, the second will execute for any negative 'a'
 
asz304 said:
Say for example
Code:
 int a = 0; 
if ( a ){
...
}


int a = 0;
if ( a < 0 ){
...
}

What's different with the first if statement? or do they have the same meaning?

Thanks

EDIT: What is the use of two-dimensional arrays? I see it mostly in file input output stream stuff.
Two-dimension arrays are useful if you have information that's in tables. One application of arrays like this is in graphics. Years ago you could write programs that would store strings of bytes to a particular location in memory that would change what was on the computer screen. Different modes (such as text vs. high resolution graphics) used memory at different locations and different amounts of memory. The screen is two-dimensional, with each row of letters or pixels corresponding to a row in a two-D array. A program could initialize an array and write it to memory and the screen would change.


asz304 said:
And how do I change the brightness of a picture using c++ using this formula:

R2 = G2 = B2 = (R1 + G1 + B1)/3

Do I need to use pass by reference?
You need to use some graphics library that has functions that change what is displayed on the screen, change the brightness, and so on. I would have to know more about what is available in the graphics package to be able to answer your question.
 
asz304 said:
Say for example
Code:
EDIT: What is the use of two-dimensional arrays? I see it mostly in file input output stream stuff.

And how do I change the brightness of a picture using c++ using this formula:

R2 = G2 = B2 = (R1 + G1 + B1)/3

Do I need to use pass by reference?[/QUOTE]

1. 2D arrays are a representation of a discrete surface: most commonly a grid. The game board of battleship comes to mind as does [PLAIN]"[URL[/PLAIN]  Game of Life[/URL], and off-course an pixel map.

2. Thats a strange formula, its probably wrong. The higher the number for each color the closer it is to white. SO, 255-255-255 is white and 000-000-000 is black. Its possible to make things whiter/lighter(?) by addition of positive increments. 

3. I don't know do you? Probably or else the changes won't carry over in the function output.
 
Last edited by a moderator:
Thread 'Have I solved this structural engineering equation correctly?'
Hi all, I have a structural engineering book from 1979. I am trying to follow it as best as I can. I have come to a formula that calculates the rotations in radians at the rigid joint that requires an iterative procedure. This equation comes in the form of: $$ x_i = \frac {Q_ih_i + Q_{i+1}h_{i+1}}{4K} + \frac {C}{K}x_{i-1} + \frac {C}{K}x_{i+1} $$ Where: ## Q ## is the horizontal storey shear ## h ## is the storey height ## K = (6G_i + C_i + C_{i+1}) ## ## G = \frac {I_g}{h} ## ## C...

Similar threads

Replies
3
Views
1K
Replies
3
Views
1K
Replies
15
Views
2K
Replies
3
Views
1K
Replies
17
Views
2K
Replies
7
Views
7K
Replies
15
Views
3K
Replies
2
Views
2K
Replies
23
Views
8K
Back
Top