Decrement numbers

How to show a series of numbers

Page 1 of 1

4 Replies - 912 Views - Last Post: 06 March 2010 - 03:00 PM Rate Topic: -----

#1 Roach86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 06-March 10

Decrement numbers

Posted 06 March 2010 - 11:45 AM

How to show a series of numbers that have been inputted by the user, and then shows it back in descending order. I was thinking of putting a for statement to receive the input of the user and then put it out.

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
	int num = 1,
		integer;

	cout << "Enter your integers that you please to input" << endl;
	cout << "then enter -99 when finished:" << endl << endl;
	cout << "Enter the integers of your choice " << num << ":" ;
	cin >> integer;

	while (integer != -99)
	{
		num++;
		cout << "Integer # " << num << " : ";
		cin >> integer;
	}

	
	cout << integer << endl;
	cout << integer-- << endl;
	cout << integer << endl;
	cout << --integer << endl;

	return 0; 
}

This post has been edited by JackOfAllTrades: 06 March 2010 - 02:58 PM
Reason for edit:: Added code tags. PLEASE!!! [code]...PUT YOUR CODE IN HERE!!!...[/code]


Is This A Good Question/Topic? 0
  • +

Replies To: Decrement numbers

#2 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: Decrement numbers

Posted 06 March 2010 - 11:49 AM

Welcome to Dream.In.Code!

One approach to your problem would be to store the numbers the user enters in an array. Then sort the array to put the numbers in order. Output the values of the sorted array.

[rules][/rules]

This post has been edited by n8wxs: 06 March 2010 - 11:50 AM

Was This Post Helpful? 0
  • +
  • -

#3 Martyn.Rae  Icon User is offline

  • The programming dinosaur
  • member icon

Reputation: 540
  • View blog
  • Posts: 1,406
  • Joined: 22-August 09

Re: Decrement numbers

Posted 06 March 2010 - 11:50 AM

Hi Roach86, welcome to Dreamincode. We have a policy here, that we need to see some effort on your part before we can help you. If you would like to post the code that you have produced, we can take a look at it. Remember to put the code between [code] and [/code] tags.
Was This Post Helpful? 0
  • +
  • -

#4 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1072
  • View blog
  • Posts: 4,532
  • Joined: 09-June 09

Re: Decrement numbers

Posted 06 March 2010 - 01:41 PM

im confused on what your trying to do , are you simple trying to do something like this
#include <iostream>

using namespace std;

int main()
{
	int num;
	cout<<"MAX NUMBER : ";
	cin>>num;

	for(int i=1; i<=anum; i++)
		cout<<i<<endl;

	cin.ignore();
	cin.get();
	return 0;
}


Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6052
  • View blog
  • Posts: 23,487
  • Joined: 23-August 08

Re: Decrement numbers

Posted 06 March 2010 - 03:00 PM

Sounds like you need to store the entered data into an array sort it, and then print out the sorted data. But without context, and with so little code -- indicating you may not even know what IS an array -- it's hard to say.

How about this?
#include <iostream>
#include <vector>

using namespace std;

static const int SENTINEL = 999;

int main()
{
    vector<int> data;
    int temp;
    cout << "Enter your integers that you please to input" << endl;
    cout << "then enter -99 when finished:" << endl << endl;
    cout << "Enter the integers of your choice :" ;

    while (cin >> temp && temp != SENTINEL)
    {
        data.push_back(temp);
    }

    if (data.begin() == data.end())
    {
        cout << "Nothing entered; goodbye!" << endl;
        return 0;
    }

    sort(data.begin(), data.end());

    vector<int>::iterator it = data.end();
    vector<int>::const_iterator itStart = data.begin();

    while (--it >= itStart)
    {
        cout << *it << " ";
    }
    cout << endl;
    return 0;
}

?

This post has been edited by JackOfAllTrades: 06 March 2010 - 03:23 PM
Reason for edit:: Mmmm...code.

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1