# Trying to sort out this c++ loop problems

Page 1 of 1

## 5 Replies - 3425 Views - Last Post: 09 March 2008 - 11:16 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=45310&amp;s=176a80ffdcd8cdc19db5f08bb64ab35d&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 gunz4sale

Reputation: 0
• Posts: 6
• Joined: 06-March 08

# Trying to sort out this c++ loop problems

Posted 06 March 2008 - 12:59 AM

Hello,

Long time lurker, first time poster. I am attempting to work on these problems and I don't even have a clue as to where I start at. #1 says

"Write a problem that calculates how much a person would earn over a period of time if his or her salar us one penny the first day, two pennies the second day and continues to double each day after. The program should ask the user for the number of days. Display a table showing how much the salary was for each day and then shows the total pay at the end of a period. The output should be displayed in a dollar amount, not the number of pennies. DO not accept a number less than 1 for the number of days worked." I don't even know where to begin working on that one.

#2 Wants me to use a loop to take 3 numbers from the user. It is then supposed to display the biggest and smallest # and then if the user enters -99 it ends the program. So far what I have done is set up a char array and told it to cin.getline 3 numbers, next I was thinking about using a for loop to display the numbers after I compare them. So my question is will a nested if statement work to end the program? My code is below:

```#include <iostream>

using namespace std;

int main()

{
char x[3];

cin.getline(x,3);

return 0;
}
```

Anyone want to point me in the right direction?

Is This A Good Question/Topic? 0

## Replies To: Trying to sort out this c++ loop problems

### #2 bhandari

Reputation: 9
• Posts: 754
• Joined: 31-January 08

## Re: Trying to sort out this c++ loop problems

Posted 06 March 2008 - 01:33 AM

Quote

I was thinking about using a for loop to display the numbers after I compare them

no need for loop as you are to display only the biggest and smallest numbers.

After doing comparison and displaying the largest and smallest numbers, take another number as input from user and if it is -99 the use if to check -99 and then call exit() to end.

### #3 gunz4sale

Reputation: 0
• Posts: 6
• Joined: 06-March 08

## Re: Trying to sort out this c++ loop problems

Posted 06 March 2008 - 01:40 AM

bhandari, on 6 Mar, 2008 - 01:33 AM, said:

Quote

I was thinking about using a for loop to display the numbers after I compare them

no need for loop as you are to display only the biggest and smallest numbers.

After doing comparison and displaying the largest and smallest numbers, take another number as input from user and if it is -99 the use if to check -99 and then call exit() to end.

The loop is part of the requirements, I wish I could do it without the loop though. And should I use an if statement to bring up the exit()? We haven't learned how to use that yet, so I guess I'll google it.

### #4 AmitTheInfinity

• C Surfing ∞

Reputation: 119
• Posts: 1,565
• Joined: 25-January 07

## Re: Trying to sort out this c++ loop problems

Posted 06 March 2008 - 02:14 AM

you can have some thing like this.

WHILE (choice !=-99)
FOR (NUMBER_CNT = 0; NUMBER_CNT <3; NUMBER_CNT++)
//Take 1 number from user
IF (NUMBER <= MIN)
MIN = NUMBER
IF (NUMBER > MAX)
MAX = NUMBER
END FOR
// Ask for user to enter choice i.e. enter -99 to exit or press any key to continue...
END WHILE

just try to implement this logic. I hope this will help you.

### #5 gunz4sale

Reputation: 0
• Posts: 6
• Joined: 06-March 08

## Re: Trying to sort out this c++ loop problems

Posted 09 March 2008 - 03:41 PM

AmitTheInfinity, on 6 Mar, 2008 - 02:14 AM, said:

you can have some thing like this.

WHILE (choice !=-99)
FOR (NUMBER_CNT = 0; NUMBER_CNT <3; NUMBER_CNT++)
//Take 1 number from user
IF (NUMBER <= MIN)
MIN = NUMBER
IF (NUMBER > MAX)
MAX = NUMBER
END FOR
// Ask for user to enter choice i.e. enter -99 to exit or press any key to continue...
END WHILE

just try to implement this logic. I hope this will help you.

That kinda makes sense, its still kinda foggy though. I'm having some trouble understanding the var you used.

This post has been edited by gunz4sale: 09 March 2008 - 03:42 PM

### #6 AmitTheInfinity

• C Surfing ∞

Reputation: 119
• Posts: 1,565
• Joined: 25-January 07

## Re: Trying to sort out this c++ loop problems

Posted 09 March 2008 - 11:16 PM

It's just the pseudo code that I have written. All you need to do is convert it to the language you want. Just look at the logic, don't care about what variables or syntax I used.