csurfer 422 Posting Pro

Too many problems in your code as I see :

string str[0];
 int i=0;
while(!myFile.eof())
{
      getline(myFile, str[i], '\n');
      vec.push_back(i);
}

line 1 : string str[0] will result in some unexpected value and not the string you want it to hold so change it to string str; but as you want to use it in getline function its better you take it as character array as char str[100];
line 3 : eof() function usage is bad and is to be avoided when ever possible,you'll find a lot of discussion in this community regarding this.Instead use good() if you want.
line 5 : Proper format of getline is istream& getline (char* s, streamsize n ); istream& getline (char* s, streamsize n, char delim ); If myfile is your file handle then call getline as:
myFile.getline(str,100,'\n');

General:
The successful number of getlines you can do with a large character array will give you the number of rows directly.
And once you have a line at your disposal then the total number of columns would be number of '\t' characters in that line plus one.

You can use this to simplify your work.

csurfer 422 Posting Pro

Daniweb suggests you not to give away the codes directly to those who ask for it.
Here you have a doubt about your work and you are free to post the part in which you have a doubt in and ask queries related to it. As long as you put in your effort you will always get help from this community.And ya read about code tags.

You have put in a good effort but this is not a C++ program.As a matter of fact even your simple algorithm is incorrect. Here are the problems :

/* sum of 10 numbers */ 
// This program computes the value of the sum of 10 numbers
#include <iostream.h>
int main ( )
{
// Define and initialize variables
float number, total, value of smallest variable;
int i = 1;
// Read in 10 numbers from the keyboard
while (i <= 10) {
if (number >1 and <99);
then (cin >> number); // read number
if ! (replace number) // read number
end if.
total = total + number; // total + number
i = i + 1; // i++
};
// Compute sum and print result;
Print smallest value;
// Exit program.
return EXIT_SUCCESS;
}

Line 7 : "value of smallest variable" is not a variable at all because variables can only contain alphabets and '_' and numbers(not in the beginning).
Line 11:You haven even read the value of "number" and before that only you are checking …

csurfer 422 Posting Pro

what is array of pointer

It literally means what it is named... Its an array of pointers.

You know this is possible right ???

char *p="Hello";
printf("%s",p);

Here it is a character pointer pointing to a string.

Same way this is also possible:

char *arr[4]={"Hello ","I ","am ","xyz."};
printf("%s%s%s%s",arr[0],arr[1],arr[2],arr[3]);

Here you have an array arr which is a collection of char * type pointers.So its an array of pointers.

csurfer 422 Posting Pro

Where is your program by the way...???

csurfer 422 Posting Pro

Make use of code tags else no one would even care to look at your code.If you use them it would look like this. For more information look here link

#include <stdio.h>
int input_number();
int main(void)
{
int numbers[100];
int counter;
int sum;
int number_elements;
printf("The number of elements you want to use is ");
scanf("%d",number_elements);
sum=0;
for (counter=1; counter<=number_elements; counter++)
{
numbers[counter]=input_number();
sum=sum+numbers[counter];
printf("The sum is %d",sum);
}
return 0;
}

int input_number();
{
int b;
printf("Input a number ");
scanf("%d",&b);
return b;
}

Errors:

Line 10 : It should be

scanf("%d",&number_elements);

Line 22 : It should just be

int input_number()
{
int b;

No semicolon after the input_number().

csurfer 422 Posting Pro

Here are your Errors...

Err 1:
Line 67 :

scanf("%d", operation2);

It should be

scanf("%c", &operation2);

Err 2:
Your macros are completely useless in this case.Even though you can change them to correct the mistake I would suggest an alternate way.

scanf("%c", operation2);
				
/* uss a switch case structure to use the user input calculator math */
switch (operation2)
{
                case 'a': 
		case  'A': total = num1 + num2;
			operation = '+';
		break;

                case 's': 
		case 'S': total = num1 - num2;
			operation = '-';
		break;

                case 'm':
		case 'M': total = num1 * num2;
			operation = '*';
		break;

                case 'd':
		case 'D': total = num1 / num2;
			operation = '/';
		break;

               case 'q':
		case 'Q': 
			total = num1 % num2;
			operation = '%';
		break;

		default: printf("Invalid Letter selected\n");
}

Err 3:
What you are doing is mixing the concepts.Don't do it. Try to clarify your doubts and have a clear conceptual of MACROS and where they are used and where do we need to sue variables.And ya also try to have a look on why fflush(stdin) is bad and should be avoided.
You'll always find help in this community as long as you show some hard work from your side.

csurfer 422 Posting Pro

Your question is very vague... Firstly Identify the type of image file you want to open...Then upon it you need to know that how many bits represent a pixel in that format then your work is very easy.
Just pick that many number of bytes and match it with the standard pixel values to tell which colour it is.It is not at all dependent on the coding language until you perform the operation properly.

csurfer 422 Posting Pro

Whenever you initialise an array partially,the un-initialised part of the array are initialised to zero's automatically.Thats the only thing which happens and as per my knowledge there is no such symbol which would function as you suggested.

For it there are two ways, one is you initialising every block value by entry using some looping construct, another is as shown below :

int array[5][5]={ {0,0,0,0,0},
                            {1,1,1,1,1},
                            {2,2,2,2,2},
                            {3,3,3,3,3},
                            {4,4,4,4,4} };
// or as
int array[5][5]={ 0,0,0,0,0,1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4 };
csurfer 422 Posting Pro

Hey this is a C question and you have posted it in a C++ forum.

If I am not wrong then you don't want to accept numbers 5 5.5 -5.5 -5 and similar...
So you can do this :

double rem;
rem=fmod(l,5.0);
if(rem > 0) printf("Not an error");
else printf("Error");
csurfer 422 Posting Pro

Here's your second fastest reply........zoooooooooom..... here it comes...

Try it your self
... and post your code here with the problems you are facing then we will be more than happy to help...

csurfer 422 Posting Pro

Ya lots of people can tell once you really start doing something...

csurfer 422 Posting Pro

I wan to say two things :

1) Read the forum rules...And let the thread head specify the topic rather than "Oh please help me.." or "Do my homework for free you dumbo's..."

2)The question is quite clear try something and then come back.
Even the looping information is given very clearly... We are here for help not as "Online free homework code portal" .

csurfer 422 Posting Pro

I wan to say two things :

1) Read the forum rules...And let the thread head specify the topic rather than "Oh please help me.." or "Do my homework for free you dumbo's..."

2)The question is quite clear try something and then come back.
Even the looping information is given very clearly... We are here for help not as "Online free homework code portal" .

And for your start :

// Headers

int main()
{
//Code the points
}
csurfer 422 Posting Pro

Hey you are posting every problem related to this hangman here at daniweb.Try something on your own.You'll learn a lot.

And indent the code properly so that its easy to read...

void Hangman::blankSpaces()
{   cout << "Your word to guess: ";
    int k,i,flag,p;
	for (k=0; k<strsz; k++)
      {  
       flag=0;
       for(i=0;i<=h;i++)
	   		if (chosenWord[k] == guess[i])
			{	flag=1;
				break;
			}
	if(flag)  // Wrongly indented in your code.
	{	cout << guess[i] << " ";
	}
	else
	cout << "_ ";
	}

Use your inCorrectguess variable here in some form may be as:

void Hangman::blankSpaces()
{   cout << "Your word to guess: ";
    int k,i,flag,p,correct_guesses=0;
	for (k=0; k<strsz; k++)
      {  
       flag=0;
       for(i=0;i<=h;i++)
	   		if (chosenWord[k] == guess[i])
			{	flag=1;
				break;
			}
	if(flag)
	{	
                   correct_guess++; // Correct_guess increments on every correct guess that is flag is set
                   cout << guess[i] << " ";
	}
	else
	cout << "_ ";

        inCorrectguess=h-correct_guess; //Here you'll get the total wrong guess count.
        // Use it in what ever form here....
}
csurfer 422 Posting Pro

Why use a for loop and looping through every character when you have predefined functions for that...???

You are reading the inputs form a text file right,just do this :

ifstream file;
file.open(<your filename>);
char str1[10],str2[10];
file.getline(str1,256,'+');
file.getline(str2,256,'\n');

Now you have the two values you wanted in str2 and str2.Use some function such as strtol to get the integer value from the string and use for your addition.

Your way of looping through every character is a complete waste when you have your file something as:

12+234
134+2334
2344+354
.
.
.
.
// 1000 or more such records.

So try to use the predefined functions.

csurfer 422 Posting Pro

This is a very generic question which can only be solved by you depending on your interests.

C and C++ help you a lot in system side programming.
Java helps you by providing a lot of utilities for application development.
Python is a very powerful language which will be the controlling phenomenon in some time.

So you decide which do you want to go into.

csurfer 422 Posting Pro

Make use of the standard functions given to you,without using that you'll never be able to exploit C to its full potential.

You can do this:
1) take the hex number as the input into a character array without the prefix "0x" or "0X" as :

char arr[10];
cout<<"Enter hex number without 0x or 0X prefix";
cin>>arr;

Now your objective of storing the different digits in different array indexes is accomplished.

2) When ever you want to use the hex number you can always do this :

long a;
a = strtol( arr , 0 , 16 );

Now you even have the decimal value of the hex number for your usage.

csurfer 422 Posting Pro

What Ancient Dragon has suggested is a wonderful suggestion try to implement it but it is completely inconsiderate with the problem in your code...

In your code :

for (int i = MAX - 1; i >= 0; i--)
        cout << output[i] << endl; //Compiling error
        if (i % 8 == 0)
            cout << "   " << endl;

This for loop is the one which is causing the error.Here even though

if (i % 8 == 0)
            cout << "   " << endl;

part should be inside the for loop according to indentation,it wont be considered inside the for loop and would be considered as this:

for (int i = MAX - 1; i >= 0; i--)
        cout << output[i] << endl; //Compiling error

 if (i % 8 == 0)
        cout << "   " << endl;

But when treated like this variable "i" is not at all declared in the function as the scope of "i" ends as soon as the for loop is over.

Therefore correct your code as this :

for (int i = MAX - 1; i >= 0; i--)
{
        cout << output[i] << endl; //Compiling error
        if (i % 8 == 0)
            cout << "   " << endl;
}

and it will work in the way you want it to work.

csurfer 422 Posting Pro

cin >> sa;

if (sa == NC)
NC = "North carolina";

else if (sa == SC)
SC = "South Carolina";

cout << "The State Abbreviation you entered stands for " << sa << endl;

Error lies here.You take sa as the input string and then you even match it improperly and finally you output sa only, that is what ever you have entered will be displayed at the output...

Try this:

cin >> sa;

if (sa == "NC")
sa = NC;

else if (sa == "SC")
sa = SC ;

cout << "The State Abbreviation you entered stands for " << sa << endl;
csurfer 422 Posting Pro

Well I am not able to get your problem exactly but from what I have got I think you can write a friend function which can read those arrays and write it conveniently to the place you want so that you have all the array values which is as good as returning all the four arrays.

csurfer 422 Posting Pro

Your code has probelms in function Hangman::blankspaces(). In it you are matching every character of the chosen character with the last guessed character and printing _ or the character for the whole word every time. thats the reason it is showing only the last selected character's place values if any.

What you need to do is to match every character of the choosen word with every guessed character till now and print accordingly.Here is a modified version of your code which may work ... try it...

void Hangman::blankSpaces()
{
    cout << "Your word to guess: ";
    int k,i,flag;
    for (k=0; k<strsz; k++)
    {
        flag=0;
        for(i=0;i<=h;i++)
        if (chosenWord[k] == guess[i])
        {
             flag=1;
             break;
        }
       
        if(flag) 
              cout << guess[i] << " ";
        else
              cout << "_ ";
    }
    cout << setw(30) << "Letters guessed so far: ";
    int p;
    for(p=0;p<=5;p++)
    {
        cout << guess[p];
    }
     cout << endl;
}
csurfer 422 Posting Pro

You are talking about a text file access through C++ and you should know that for it there is no concept of line,its just a stream of characters and the compiler knows that it should print the characters following '\n' character in the next line.
Using this '\n' as a line delimiter getline() function has been designed.
After knowing how it works you can design your own function to suffice your needs.

csurfer 422 Posting Pro

Ya I too feel this is TC that you are working on.So I would suggest this...

1) You can always play with the co-ordinates when working on TC, like usage of gotoxy( x , y ) To move to a particular part of the screen and then print the stuff you want by using settextcolor() (I am not sure if this is the command just type "textcolor" and put your cursor there and press Cntrl F1 you'll get help).

2) Another thing I would like to suggest here is usage of "viewport" concept here so that you can clear and modify only a part of the screen rather than redrawing the whole screen.

csurfer 422 Posting Pro

Looks ok to me. The only problem I see is that >> operator will not allow the file name to contain spaces. You need to use getlin() if you want spaces.

Why do you think the code you posted does not work?

Thats getline() what Ancient Dragon wanted to say and dont worry you wont need it because filenames don't contain spaces in them and you are using it for files. ;)

csurfer 422 Posting Pro

Well here's a starter for you :
Let the class be something like this ...

class stack{
int arr[50]; //To create a stack of size 50 
int top=-1; //Initial value for the variable holding the top position in the stack;
public:
int push(int x); //Function which takes x as the parameter and pushes it into the array after checking the limits by arr[++top]=x make this function return 1 on success and 0 on failure
int pop(); //Function which implements return arr[top--] make this function return the top value on success and 0 on failure.
void display(); //Make this function display contents of the stack in top to down manner
};

Once you successfully implement this convert it into a better stack by use of template functions.

csurfer 422 Posting Pro

Hey tux that was the assignment given by4101 to you. Do it sincerely...You'll learn a lot ;)

csurfer 422 Posting Pro

It must mean that quizMaster.isCorrectAnswer(answer) is always returning 0 .Just check in that particular function for solving the problem. Its quite straight forward right.

csurfer 422 Posting Pro

Or a brute force approach would be something like this :

int total;//this holds the number of random numbers to be generated
//Assume you want to generate random numbers between 50 and 70
int cnt=0;//This hold the number of random numbers already generated.
while(cnt<total)
{
//Generate the random number between 1 and 70 say number is rnum
while(rnum<50) 
{
    //generate rnum again
}
cnt++;
}
csurfer 422 Posting Pro

You haven got anything such as int random(int); .

For generation of random numbers you have got the function rand which is of the format int rand(void); .Defined in cstdlib.You will get more information in this <link>.

csurfer 422 Posting Pro

Little corrections to both the posts given above with some information:

@23.12.2012:

Here s1+=8; doesn't really help because ASCII value of 8 is '\b' character the backspace character.And by executing the above statement with earlier string s1 which was "Hello World! I am" we get "Hello World! I am\b" as a result of which we get just "Hello World! I aToday!" in the output.

@daviddoria:

Casting 8 to a char or to say (char)8 would result in the same situation as stated above as the compiler tries to find the character with ascii value 8 which results in backspace again.

@Both:

Treating 8 itself as a character rather than ASCII is done by enclosing it with single quotes as '8'.Using this the output of "Hello World! I am 8 Today!" can be got by the following code :

s1 = s3 + " " + s4 + " ";
s1 += '8';
cout << s1 + " " + s2 + "!\n";

The thing which the OP has done above by the statement s1 += " 8 "; is concatinating s1 with the string " 8 " i,e <space>8<space>.Here the string " 8 " is used directly and it has no relation with respect to casting of 8 to character or anything.Its just a string concatination to another string.

csurfer 422 Posting Pro

i think these posts ought to be instantly deleted by moderators, along with a copy of a standard explanation auto-delivered to the poster's email.

I can see why Narue has all but left daniweb ... because it's this kind of non-stop crap just makes me want to flame the hell out of people who post it. I don't even want to waste my time trying to explain why they won't get help.


.

Its just a matter of time jephtah .Once we stay here for as long as Narue or you then we too would feel the same.
The only exception is Ancient Dragon who still deals with these things with patience ;) .Hats off to his patience and experience.

csurfer 422 Posting Pro

Apart from what Hiroshe has rightly stated,I would like to add these (after all corrections stated by Hiroshe):

1>

if (IsPrime(num)==(true));
{
printf("%d\n", num);
}

No semicolon at the end of if and don't do redundant work as in IsPrime(num)==(true) the following is enough:

if (IsPrime(num)) //No semicolon and a return of 1 is enough no need to recheck with "==" op.
{
printf("%d\n", num);
}

2>
And in your IsPrime function with this line :

for (i=3;i<=limit;i+=2)

You can still cut down the number of checks by checking only with the prime numbers <=limit as the rule says "If a number cannot be completely divided by any prime number <= its square root then that number is a prime".
Of course this doesn't matter much when the limit is 100 but for higher limits it counts a lot.

csurfer 422 Posting Pro

The thing you are forgetting is that the concept of lines appear only in case of display to the terminal or in general just the display.While storing there is nothing called a separate line,it is just signified by the '\n' character which tells the display program to start printing in next line.
So it doesn't really matters whether you read the whole line (as how you see it ) or just 256 characters ( limiting to the buffer size ) because until the order of characters doesn't change and until there is the presence of '\n' character your alignment wont change. :)

And ya the unlimited buffer,there is nothing of that sort.You need to allocate the memory and then use it.

csurfer 422 Posting Pro

All the post above are true especially have a look at link given by DaveSinkula.Here I will just go with the basics to help you know the concept.

What is main actually ?
Main is the function which is called before all functions when we execute a C or C++ program.So that must mean it should be called by something and it should return something.

So why not void main() ??? That is because main is the function which is called by the operating system through some start up routine and that start up routine decides success or the failure of the program on the basis of the value returned from main.

So now we can say that a return value which is an integer is needed for main as the start up routine calls main as something like this :

exit( main() );

Now for the question which is better int main() or int main(void) ?Both are ok and compilers would consider both calls as right but sometimes it would be better to specify int main( void ) tp tell the compiler right away that we are not taking any values form the command line by specifying "void" in place of arguments to main function.

MosaicFuneral commented: QC scrutinized, and gladly passed. +6
csurfer 422 Posting Pro

Read the two dimensional array elements one by one and feed them sequentially into the single dimension array, thats it.

csurfer 422 Posting Pro

Mistake:

for (i = 0; line[i] = NULL; i++);

1>Remove the semicolon at the end of this statement.
2>It should be line!=NULL and not line=NULL.

csurfer 422 Posting Pro

Try installing the lib folder again... from some other copy...Its a common problem in TC...you wont have that problem again once you replace that folder with the proper ones.

csurfer 422 Posting Pro

dear, Mr. David...
I'v tried but it's still not work.
there's an error :: error C2440:'initilizing' : cannot convert from'const char *' to 'System::Byte^'

I want to split the string per line sir: example:
str = 111,222,333
i want it be(after I remove the delimiter ','):
111
222
333
so, it easy if the str, i convert to an array of char.
i'v tried this:
marshal_context ^ context = gcnew marshal_context();
const char* str4 = context->marshal_as<const char*>(str);
puts(str4);

but it's still not work.
thanks.

Firstly why do you want to read the complete line and then split it with delimiter as "," ...???

Why not directly use

istream::getline(char* s,streamsize n,',');

with this you can directly read only upto the "," and hence get it in the format you actually want rather than reading the whole line first and then splitting it.

csurfer 422 Posting Pro

Well we will help you for sure.Here are a set of good books from which you can learn.<USEFUL BOOKS>.
Read all this write a program and then if you have problems come back with your code we will do more than just helping you.Till then enjoy your studies.You wont get any help here.

This is a community for learners and no help is given to lazy people.

I wont say that you are chickening out of writing codes or getting lazy but until you try you wont be able to code.So start your coding now and we will help you with all our might.

We too started the same way and soon you will be one among us so start coding and start studying.

csurfer 422 Posting Pro

Use code tags specific to a language it would be better. :)

Few mistakes present:

1>
//Validate the input.

while (scores < 0)
{
cout << "Zero or negative numbers not accepted.\n";
cout << "Test Score #" << (count + 1) << ": ";
cin >>scores[count];
}

This should be:

//Validate the input.
while (scores[count] <= 0)
{
cout << "Zero or negative numbers not accepted.\n";
cout << "Test Score #" << (count + 1) << ": ";
cin >>scores[count];
}

2>

void showAverage(float, int);

change this to

void showAverage(float, int, float);

3>

showAverage( total, numScores );

//Get lowest

lowest = scores[0];
for ( int count = 1; count < numScores; count++)
{
if(scores[numScores] < lowest)
lowest = scores[numScores];
}

Change this to

//Get lowest

lowest = scores[0];
for ( int count = 1; count < numScores; count++)
{
if(scores[numScores] < lowest)
lowest = scores[numScores];
}

showAverage( total, numScores , lowest);

//Then go on with your deletion of allocated memory.

4>

void showAverage(float total, int numScores)
{
float average;

//Calculate the average
.
.
.
.
}

change this to

void showAverage(float total, int numScores ,float lowest)
{
float average;

//Calculate the average
.
.
.
.
}
csurfer 422 Posting Pro

Few things I found out :
1>Your stdafx.h header is not a compulsion.The program is running even without that header and giving the desired results.
2>The space in the input by the user after the comma is critical.If something like Montoya,Inigo would result in answer nmontoya rather than imontoya.So add a check to your program to check the space after the comma and display that input is not proper if that format is not found.

csurfer 422 Posting Pro

Remove the & pass by reference symbols from the functions

void generate_array(int& f_array[]);
void print_array(int& p_array[]);

Let the functions just be:

void generate_array(int f_array[]);
void print_array(int p_array[]);

It works fine...

csurfer 422 Posting Pro

Whats with return getchar() ? You got several other ways to pause the output.Use one of them rather than this because even though you return some random character as the return of main and exit the OS thinks that the process didn't terminate properly because of a non zero return value.Which of course doesn't cause any problem here but would definitely cause great problems in future when you write some important code.
So better correct it now.

csurfer 422 Posting Pro

Your question is completely dependent on the fact as to "How type safe is the language we are using?" Languages which assure complete type safety assure the release of memory at the end by the process of "Garbage Collection".
Even though C++ is a type safe language it entertains several features of C language just for the sake of backward compatibility and this is what prevents us from developing an effective Garbage Collector for C++ because an effective garbage collection is possible only in case of complete type safe languages and C++ doesn't reach the 100% mark.
It further depends on how your OS is as some take specific care about every memory allocated even if its in a type unsafe language.

So with all these things in mind its always better not to rely on the inbuilt Garbage collector provided by the language or by the OS and free the memory ourselves.

csurfer 422 Posting Pro

I think it is a great way to explain the simplicity of C++. You will have to fight off the newbies wanting to learn if you show them the clear and intuitive code that can be written:

int main(){X*p;std::cout.operator<<(*(X*)&((*new X(&p))()=10)).put(10);delete p;}

:D

I will leave the simple definition of X as an exercise for the reader.

I agree with your
way of explanation Tom Gunn But the OP's question is not manipulating the pointer to a class inside main function but to manipulate it inside the class itself and I don't think you have spoken anything in that regard.

csurfer 422 Posting Pro

Ya it is something like an object pointing to itself. Even though you may try to code it for experimentation you wont get any benefits from it and i dont even see a specific use....That is the reason i wanted you to be more specific about you requirement (not about your stated question) as to how and where are you using it?And why?

csurfer 422 Posting Pro

My action was a sincere effort to preserve the essence and culture of this community by telling a newbie more about Daniweb. Sorry if you guys (jephtah,tom gunn) felt it was extreme. By the way thanks for letting me know by -ve rep.Will take care from next time.

csurfer 422 Posting Pro

Your question is cyclic :
1>A pointer to a particular class cannot be defined until the class is defined.
2>And you want to define the pointer to the class and manipulate it within the constructor of the class itself.

Which is interdependent.So ask your question clearly and state your exact requirement in a more understandable way.

csurfer 422 Posting Pro

You mean to say Ten Point Three Eight is represented as 10,38 rather than 10.38 ???

Well if the answer to the above question is yes then of course you cant use the float data type for your work.So define your own data type something as follows:

class myfloat{
private:
string temp;
int bef_decpoint;
int aft_decpoint;
float value;
public:
//Some functions
};

Now what you can do is this:

1>Read in the string 10,38 up till "," into temp.

2>

//To get the integer value
istringstream out(temp);
out>>bef_decpoint;

3>Read in string 10,38 after the "," till '\0' (not including) into temp.

4>

//To get the numeric value of aft_decpoint
istringstream out(temp);
out>>aft_decpoint;
//To get the floating value
value=(float)bef_point+(float)aft_point / (10*temp.length());

5>Use it as you want now.

You didn't want to change the file so this is one of the "Brute force" ways to solve your problem.
Sky diploma has provided a far better way but with this approach you can use the "before ." and "after ." as separate entities in case you need it. :)

csurfer 422 Posting Pro

Just an added information :

It is called as scope definition.It is C's way of assuring something similar and far less effective "Encapsulation" technique provided by C++.
It is a way by which we set a boundary to the usage of a specific variables.It is a way in which we define where is a particular variable valid.Example:

//scope 1
{
     //scope 2
    {
          //scope 3
          {
                 //goes on
          }
    }
}

Some basics:
1>Variables declared in scope n are valid and can be used in scope m where n<m.
2>Variables declared in scope n have no meaning in scope m when n>m.
3>In case a variable with same name x is defined in scope n and scope m where n<m and operation on variable is carried out in scope m then the local value of x that is variable x of scope m is used.(General Rule : More local value will be used in the case of conflicts as above).
4>The above concept is just used to set boundaries for the variables.As shown above if a variable is declared in scope n then we limit its usage to scope m where m>=n but not in m<n.