Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,122 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,989 people online right now. Registration is fast and FREE... Join Now!




Loop through 2 given numbers n1 and n2

 
Reply to this topicStart new topic

Loop through 2 given numbers n1 and n2, homework question need help

kazamatsurishou
post 7 Oct, 2008 - 06:19 PM
Post #1


New D.I.C Head

*
Joined: 7 Oct, 2008
Posts: 2


My Contributions


one of my homework quesstion is:
Write a program to print all the numbers from n1 to n2, where n1 and n2 are two numbers specified by the user.

How am I going to start writing the program?
User is offlineProfile CardPM

Go to the top of the page

no2pencil
post 7 Oct, 2008 - 06:22 PM
Post #2


My fridge be runnin OH NOEZ!

Group Icon
Joined: 10 May, 2007
Posts: 6,324



Thanked 57 times

Dream Kudos: 2375

Expert In: Goofing Off

My Contributions


QUOTE(kazamatsurishou @ 7 Oct, 2008 - 10:19 PM) *

How am I going to start writing the program?

On a realistic level... with a text editor or IDE.

Surely you don't have an assignment without having gone over the material in class 1st?

Tutorial on passing arguments to int main
& a for loop syntax :
cpp

for(int i=0;i<MAX;i++) {
// Perform looping stuff...
}
User is offlineProfile CardPM

Go to the top of the page

Linkowiezi
post 8 Oct, 2008 - 01:34 AM
Post #3


D.I.C Head

**
Joined: 7 Oct, 2008
Posts: 67



Thanked 11 times
My Contributions


QUOTE(kazamatsurishou @ 8 Oct, 2008 - 03:19 AM) *
How am I going to start writing the program?


Of course I have to say the same as no2pencil to begin with:
QUOTE(no2pencil @ 8 Oct, 2008 - 03:19 AM) *
On a realistic level... with a text editor or IDE.

Then I don't know hw much you know about programming.
Do you need help with finding and setting up an IDE and/or a compiler to begin with?
Or if you have managed to do that already you should try to write a code and post it here so we can help you.
We won't do the assignment for you but we can help you if you get stuck somewhere.
Below I have put down a few leads for you by using the comments I would use to describe the code in a program that would do what you are asking for.

C++
//  Includes
// Namespaces

// Main function
// Declaration of integers
// User input
// for-loop where the numbers between n1 and n2 are printed on the screen
// Return 0 to let the OS know the program ran successfully
User is offlineProfile CardPM

Go to the top of the page

Sadaiy
post 8 Oct, 2008 - 07:26 AM
Post #4


New D.I.C Head

*
Joined: 3 Oct, 2008
Posts: 34



Thanked 1 times
My Contributions


here is exactly what you must type:

but note that this assumes the second number entered is larger than the first number!

cpp

#include <iostream>

using namespace std;

int main()
{
int n1, n2;

cout << "Please enter two numbers: " << endl;
cin >> n1 >> n2;

for(n1; n1 <= n2; ++n1)
{
cout << n1 << " ";
}

return 0;
}


This post has been edited by Sadaiy: 8 Oct, 2008 - 07:27 AM
User is online!Profile CardPM

Go to the top of the page

overlord_shimra
post 8 Oct, 2008 - 11:12 AM
Post #5


New D.I.C Head

*
Joined: 7 Oct, 2008
Posts: 13



Thanked 1 times
My Contributions


dude... don't do the homework for him. it says it right in the text box where you responded.
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/21/08 11:08AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month