-1

I am a newbie. And I want to do this program without using array and only with 3 variables. Looking forward for your help. I stuck up here:

#include<iostream>
#include <math.h>
using namespace std;

int main()
{
    float a,b,c;

    cout << "Please Enter the numbers: " << endl;
    for(float k=0; k<=9; k++)
    {
        cout << "Enter number " << k+1 << " : ";
        cin >> c    
    }
}

I am not getting the part how to take the values in a & b and compare them with each other. Please let me know if I am heading towards wrong direction. looking forward for the help.

Thanks in advance.

Regard, Sam

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
SAM
  • 25
  • 2
  • 8
  • 11
    Please, at least show some effort. We're not here to do your homework for you. – Fred Foo May 26 '11 at 16:05
  • is that homework? you it is you shold tag it – Heisenbug May 26 '11 at 16:05
  • @SAM: This sounds like a homework assignment. Please tag it as such. Also, consider reading a [book](http://stackoverflow.com/questions/388242/). – Björn Pollex May 26 '11 at 16:06
  • Show us your code how it is now and you will surely be helped. – Hyperboreus May 26 '11 at 16:06
  • 4
    Looking forward to seeing some input from you, followed up by a question about something specific. Thanks in advance. – Lightness Races in Orbit May 26 '11 at 16:06
  • the variables are: previous number; count of read munbers to the time; current number. – osgx May 26 '11 at 16:06
  • how would you do it by hand? If i were to say 10 numbers to you and ask at the end if they were in order? what notes would you make on paper? Once you know that, you should be able to code it. – Kate Gregory May 26 '11 at 16:06
  • sorry friends, I was being too childish here!! I stuck in half since the condition not to use array.. But thanks anyway for having a look at my question. Sorry to consume your time. – SAM May 26 '11 at 16:46
  • What you have looks reasonable now, voting to reopen. Btw, what do you mean with "how to take the values in a & b and compare them with each other"? – Xeo May 27 '11 at 01:06
  • since the condition is not to use array, I have to compare the numbers which I have taken and there is my problem, how to do this with 3 integers? And thanks Xeo for voting. – SAM May 27 '11 at 01:10
  • @SAM: Basically, save the values of the last and the current input, and then check if they are ordered. If not, then the whole sequence won't be ordered. Btw, you can notify someone of your comment by typing `@Name` in the beginning like I do. – Xeo May 27 '11 at 01:44
  • @Xeo: yeah, i got the approach! but how to verify the value previous than the previous value? I mean dont we need to use array for that? – SAM May 27 '11 at 09:15
  • @SAM: `bool isOrdered = a < b`? where `a` is from the previous input and `b` is from the current input. – Xeo May 27 '11 at 09:19
  • @Xeo: ahh, i got it now! thanks for the help friend. I will try it now. – SAM May 27 '11 at 10:02
  • @SAM: I think you need to get a [good book](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) if you didn't even know of `<`. :) – Xeo May 27 '11 at 10:05

1 Answers1

1

You only need two variables, not three.

#include <iostream>
#include <limits>

using namespace std;

int main(int argc, char* argv[]){

  float old = std::numeric_limits<float>::min(), current = 0.f;

  for(int i = 0; i < 10; i++){

    std::cin >> current;

    if(current > old){
      old = current;
    }else{
      std::cout << "Not ascending order!" << std::endl;
      return 0;
    }
  }
  std::cout << "Ascending order!" << std::endl;
  return 0;
}
Arlen
  • 6,641
  • 4
  • 29
  • 61