Getting Started With C++ [Solved]

Posts 1–7 of 7 · Page 1 of 1
Getting Started With C++ [Solved]
Alright so im just starting C++ and im reading C++ without fear the second edition and i just really needed some basic help with understanding what do i have to do to print all the numbers from n1 to n2 where n1 and n2 are two numbers specified by the user. Im using the program dev-c++ as my compiler. Thanks
Well, you will first need to define n1 and n2 as an int variable sinice they will be integers:

int n1, n2;


Then you will use the cin function to get user input:

std::cin>>n1;
std::cin>>n2;

Then you will want to print it, so you use the cout function:

std:: cout<<"First number is: "<<n1<<"\nSecond number is: "<<n2;


Keep us posted on your progress.
Quote Originally Posted by 258456 View Post
Well, you will first need to define n1 and n2 as an int variable sinice they will be integers:

int n1, n2;


Then you will use the cin function to get user input:

std::cin>>n1;
std::cin>>n2;

Then you will want to print it, so you use the cout function:

std:: cout<<"First number is: "<<n1<<"\nSecond number is: "<<n2;


Keep us posted on your progress.
He wants to print all the numbers in the range of n1 and n2 (inclusive).

Code:
#include <iostream>
#include <conio.h>
using namespace std;
void main()
{
int n1,n2;
cout << "Enter 1st Number: ";
cin >> n1;
cout << "Enter 2nd Number: ";
cin >> n2;
for(int x = n1;x<=n2;x++) //Initialize x to the number stored in n1. Then loop while x is less than or equal to the number stored in n2. (x++ increments the value of x after each iteration.
{
cout << "Number is: " << x << endl;
}
_getch();
}
Quote Originally Posted by Hassan View Post


He wants to print all the numbers in the range of n1 and n2 (inclusive).

Code:
#include <iostream>
#include <conio.h>
using namespace std;
void main()
{
int n1,n2;
cout << "Enter 1st Number: ";
cin >> n1;
cout << "Enter 2nd Number: ";
cin >> n2;
for(int x = n1;x<=n2;x++) //Initialize x to the number stored in n1. Then loop while x is less than or equal to the number stored in n2. (x++ increments the value of x after each iteration.
{
cout << "Number is: " << x << endl;
}
_getch();
}
Oops, my bad, i misread his post.
Thanks for the help!
Np. Marked Solved.
I was interested in making a Kill/Death Ratio Hack for Modern Warfare 3 can anyone help me get started? I just started to read some C++ books and i really need some professional help.

Thank you
Posts 1–7 of 7 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?