please help me to get the coding please

J

JetQi Tan

Modify the program to ask two integer numbers from the user and then
output all the integer numbers in
between these two numbers. Assume that the user will enter the first
number to be smaller than the
second number
 
S

Saeed Amrollahi

 Modify the program to ask two integer numbers from the user and then
output all the integer numbers in
between these two numbers. Assume that the user will enter the first
number to be smaller than the
second number

Hi
I'm pretty sure, it's a homework and we don't help you in doing
assignment. I encourage you, to write it: Use standard input,
to read two numbers, then use a for or while loop to enumerate
numbers from first to second number and prints them
to standard output.
Come back with a piece of code.

Good luck
-- Saeed Amrollahi
 
J

JetQi Tan

#include <iostream>
using namespace std;


int main()
{
int sum;
int num1;
int num2;

cout << "Enter first number:";
cin >> num1;

cout << "Enter second number:";
cin >> num2;


while ( num1 < sum < num2 )
{
cout << sum << " ";
sum = num1 + 1;
}


return 0;
}

(am i wrong?)
 
G

gottloser Vaterlandsverraeter

Am 02.07.2011 04:01, schrieb JetQi Tan:
Modify the program to ask two integer numbers from the user and then
output all the integer numbers in
between these two numbers. Assume that the user will enter the first
number to be smaller than the
second number


///////////////////////////////////////////////////////////////////////
/* to compile run:
*
* g++ -o numbers numbers.cpp
*
*/

// include the iostream functionality from iostream.h
#include <iostream>

using namespace std;

// main function
main(){
cout<< "Enter first number"<< endl;
int first, second;
cin>> first;
cout<< "Enter second number"<< endl;
cin>> second;
for(int counter = first;
counter <= second;
counter++){
cout<< counter<< ", ";
}
cout<< endl;
}
/////////////////////////////////////////////////////////////
 
S

Saeed Amrollahi

#include <iostream>
using namespace std;

int main()
{
   int sum;
   int num1;
   int num2;

   cout << "Enter first number:";
   cin >> num1;

   cout << "Enter second number:";
   cin >> num2;

   while ( num1 < sum < num2 )
   {
   cout << sum << " ";
   sum = num1 + 1;
   }

   return 0;

}

(am i wrong?)

Now, it's good. You came back with your code.
I guess, you are going to modify your previous program:
"write a program to sum from 1 to n or some similar programs."
In this program you don't need to sum variable at all. Also,
num1 < sum < num2
doesn't work as you expected.

-- Saeed Amrollahi
 
I

Ian Collins

On 07/ 2/11 07:37 PM, JetQi Tan wrote:

Please keep the part of the previous post you are replying to and who
posted it.
#include<iostream>
using namespace std;


int main()
{
int sum;
int num1;
int num2;

It is generally better to declare variables just before you use them.
cout<< "Enter first number:";
cin>> num1;

cout<< "Enter second number:";
cin>> num2;


while ( num1< sum< num2 )

This is a really strange expression! What value should sum start at and
whet value should it end before? Try using a for loop, it should then
be much clearer to you.
{
cout<< sum<< " ";
sum = num1 + 1;

This is causing an infinite loop. You want to increment sum here, not
fix its value.
 
J

JetQi Tan

thanks a lot..u guys realy help me a lot,i dnt understand what my
teacher said,i will try it now
 
M

MikeP

JetQi said:
Modify the program to ask two integer numbers from the user and then
output all the integer numbers in
between these two numbers. Assume that the user will enter the first
number to be smaller than the
second number

Only The Architect can modify the program (I assume you are not Neo). You
should probably seek The Oracle or The Keymaker for more insight/help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top