|
-
April 7th, 2009, 07:48 AM
#1
[Newbie] Putting variables into an order
Hello,
First I would like to welcome myself and say hi, I love the site and have spent a little time reading and just started writing some C++ to play around with. All of my code is written for the console at the moment and I hope to change that one day, but one step at a time.
I have two problems, I am not expecting someone two write the code for me but to point me in the right direction would be tops.
Problem 1.
I am using cin to put data into my program, I am then storing the data as a float. I have around 10 floats, I would like to then put those floats in running order from lowest to highest and give them a new syntax (i think it is that, called please correct me if I am wrong) or in lame terms a new float variable.
An example of what I want is
float number1 = 1
float number2 = 15
float number3 = 4
float number4 = 40
to become
float next1 = 1
float next2 = 4
float next3 = 15
float next4 = 40
I am also aware those are whole numbers and should be using int, but it is just an example and I wish to have the use of decimals
Problem 2.
I know I can write a lot and lot of code to "brute force" what I want but I am hoping for a simple solution, the easiest way I can explain this is the card game 21. I want my program to select the x number of floats and get nearest to 21 without going over 21.
I will be very grateful for any help I can receive, I am totally a newbie here asking newbie questions but am trying to learn something by coding something practical in my eyes.
Thanks a lot guys, much appreciated.
Last edited by Ancient; April 7th, 2009 at 07:51 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|