# Need help in initializing my increment operator

Page 1 of 1

## 3 Replies - 783 Views - Last Post: 04 September 2012 - 05:07 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=290970&amp;s=ed90688a2b6982789fe294ec454e80dc&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 zachkt

Reputation: 0
• Posts: 41
• Joined: 19-July 12

# Need help in initializing my increment operator

Posted 04 September 2012 - 04:37 PM

I'm trying to make a program that asks for a starting and final temperature then finds the velocity at the given temperature. But i need to use the increment operator so that i can get the velocity at each temperature between the two numbers. For example if the numbers were 5 and 10, then i need to find the velocity at teach temp between 5 and 10 degrees.

```
#include <iostream>
using namespace std;
int main ()
{
int starttemp;
int endtemp;
double velocity;
int tempchange;
int count;

cout << "Please enter the initial temperature\t";
cin >> starttemp;
cout << endl;
cout << "Please enter the final temperature\t";
cin >> endtemp;
cout << endl;

tempchange = endtemp - starttemp;
velocity = 331.3 + 0.61 * tempchange;

cout << "At" << starttemp << "degrees Celsius the velocity of sound is " << velocity << endl;

while ( count ++ <= endtemp )
{
cout << "At" << count << "degrees Celsius the velocity of sound is " << velocity << endl;
}

cout << "At" << endtemp << "degrees Celsius the velocity of sound is " << velocity << endl;

return 0;

}

```

Is This A Good Question/Topic? 0

## Replies To: Need help in initializing my increment operator

### #2 Skydiver

• Code herder

Reputation: 4376
• Posts: 14,124
• Joined: 05-May 12

## Re: Need help in initializing my increment operator

Posted 04 September 2012 - 04:54 PM

Why not use a simple for loop between start temp and end temp, and compute the appropriate velocity for a given temperature with in the loop?

Something like this which computes y = x2:
```for(int x = 0; x < 5; x++)
{
int y = x * x;
cout << "x: " << x << " y: " << y " << endl;
}

```

### #3 zachkt

Reputation: 0
• Posts: 41
• Joined: 19-July 12

## Re: Need help in initializing my increment operator

Posted 04 September 2012 - 05:00 PM

Skydiver, on 04 September 2012 - 04:54 PM, said:

Why not use a simple for loop between start temp and end temp, and compute the appropriate velocity for a given temperature with in the loop?

Something like this which computes y = x2:
```for(int x = 0; x < 5; x++)
{
int y = x * x;
cout << "x: " << x << " y: " << y " << endl;
}

```

you confused me with the int y = x*x. I am assuming the "X" refers to "count" in my code. What does the "Y" stand for velocity?

### #4 Skydiver

• Code herder

Reputation: 4376
• Posts: 14,124
• Joined: 05-May 12

## Re: Need help in initializing my increment operator

Posted 04 September 2012 - 05:07 PM

Yes.

In your code, you would use a variable named velocity instead of y. You would also use a variable named temperature instead of x. Obviously, you would use a different formula, than the one I used. Using the for loop you would make temperature range from the start temperature to the end temperature by incrementing the value each time through the loop.