5 Replies - 3416 Views - Last Post: 09 March 2008 - 11:16 PM Rate Topic: -----

#1 gunz4sale  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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];
	
cout<<"Please enter 3 numbers"<<endl;
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  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 9
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#3 gunz4sale  Icon User is offline

  • New D.I.C Head

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

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

Posted 06 March 2008 - 01:40 AM

View Postbhandari, 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.
Was This Post Helpful? 0
  • +
  • -

#4 AmitTheInfinity  Icon User is offline

  • C Surfing ∞
  • member icon

Reputation: 119
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#5 gunz4sale  Icon User is offline

  • New D.I.C Head

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

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

Posted 09 March 2008 - 03:41 PM

View PostAmitTheInfinity, 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

Was This Post Helpful? 0
  • +
  • -

#6 AmitTheInfinity  Icon User is offline

  • C Surfing ∞
  • member icon

Reputation: 119
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1