473,394 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

help with errors-confused

hello,i'm a student and i'm in my first year.

i had an assignment using borland c++ and this is what i made

#include <iostream.h>
#include <conio.h>

int main ()
{
int number,odd,even,small,big;


odd = 0;
even = 0;
small = number;
big = number;

cout << "Enter a number: \n";
cin >> number;

while (number != 0)
{
number == 0;
{

if (number %2 = 0)
even = even + 1;
else
odd = odd + 1;
}
{
if (number < small)
number = small;
else
{
if (number > big)
big = number;
else
endl;
}
}

}

cout << "\nThe biggest number is " << big << endl;
cout << "\nThe smalest number is " << small << endl;

cout << "\nThere is " << even << " even numbers." << endl;
cout << "\nThere is " << odd << " odd numbers." << endl;



getch ();

return 0;

}

but it had these errors:

cpp (11,11) : possible use of 'number' before definition
cpp (21,23) : Lvalue required

i tried looking up on the internet on how to fix these errros but somehow i got more confused.

could someone please help me..

on how to fix those errors and explain to me what is 'Lvalue' and 'possible use of 'number' before definition' mean.

p/s: sorry if my english is not good.and if you could, please make the explanation in simple english.^_^
Feb 18 '09 #1
9 3688
donbock
2,426 Expert 2GB
"possible use of 'number' before definition"
This message typically means that you are reading a variable (in this case, 'number') before anything was written to it.

"Lvalue" or "L-value" refers to something that either could or actually does appear on the left side of an equals sign. (This is a simplified definition; it is actually more complicated than that. You should google the term for more accurate information.)

"Lvalue required"
This message typically means that you have a non-Lvalue on the left side of an equals sign. (As you might expect, a non-Lvalue is called an "Rvalue" or "R-value".)

For error message "cpp (n1,n2) text", the error occurred near line n1 of your source code. I don't know what n2 means.

Remember that a single equals sign (=) is used to assign the value on the right side to the variable on the left side; while a double equals sign (==) is used to test whether two values are equal.

You have unusual bracing style.

You probably want to acquire a new value for 'number' every time you pass through the loop. Be careful to keep the proper relative order of getting a new 'number' value and testing for loop termination.
Feb 18 '09 #2
whodgson
542 512MB
This compiles:
//19/02/09 15:28
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <conio.h>
  3. using namespace std;
  4.  
  5. int main ()
  6. {
  7. int number,odd=0,even=0,small,big;
  8.  
  9. small = number;
  10. big = number;
  11.  
  12. cout << "Enter a number: \n";
  13. cin >> number;
  14.  
  15. //while (number != 0)
  16. //{
  17. //number == 0;
  18. //{
  19.  
  20. if (number %2 == 0)even = even + 1;
  21. else odd = odd + 1;
  22.  
  23. if (number < small)number = small;
  24. else if (number > big)big = number;
  25. else cout<<endl;
  26.  
  27. cout << "\nThe biggest number is " << big << endl;
  28. cout << "\nThe smalest number is " << small << endl;
  29.  
  30. cout << "\nThere is " << even << " even numbers." << endl;
  31. cout << "\nThere is " << odd << " odd numbers." << endl;
  32.  
  33. getch ();
  34.  
  35. return 0;
  36.  
  37. }
....and outputs this:
/*Enter a number:
47

The biggest number is 47

The smalest number is 2

There is 0 even numbers.

There is 1 odd numbers.*/
Feb 19 '09 #3
JosAH
11,448 Expert 8TB
@whodgson
But it doesn't run correctly:

1) you're assigning uninitialized numbers to some variables.
2) your loop is bogus.
3) check the output: where does that '2' come from?

Please check and double check your code before you post it.

kind regards,

Jos
Feb 19 '09 #4
thank you for the responds.

as for my bracing style, i dont know what to say because that's what our lecturer taught us and even in our textbook (the author is one of our lecturer) stated the same bracing style.

the errors had been fixed and compiling it is a success.Thank you for helping.

but there's another problem.

after editing:

#include <iostream.h>
#include <conio.h>

int main ()
{
int number,even = 0,odd = 0,small,big;



cout << "\nInput an integer, one at a time, and press enter.\n";
cout << "Enter the numbers as many as you want.\n";
cout << "Enter integer 0 to stop.\n";
cout << "Enter number: \n";
cin >> number;

small = number;
big = number;

while (number != 0)
{
number == 0;
{
if ((number % 2) == 0)
even = even + 1;
else
odd = odd + 1;

if (number < small)
number = small;
else
{
if (number > big)
big = number;
else
endl;
}

}

}

cout << "\nThe biggest number is " << big << endl;
cout << "\nThe smallest number is " << small << endl;

cout << "\nThere is " << even << " even numbers." << endl;
cout << "\nThere is " << odd << " odd numbers." << endl;

getch ();
return 0;

}


---------

when i run this program,

this came out:


Input an integer, one at a time, and press enter.
Enter the numbers as many as you want.
Enter integer 0 to stop.
Enter number:
8

------

but after i type the number '8', i cant enter another number.means typing any number caused no effect to the output.what should i do to fix it?

--------
Feb 20 '09 #5
donbock
2,426 Expert 2GB
Regarding brace style ... I was referring to the open-brace that immediately precedes the first "if" statement (and the matching close-brace). What do you intend to accomplish with this pair of braces? I'm not saying this is a mistake; I'm only concerned that you're trying to accomplish something that isn't getting done.

Regarding entering multiple numbers ... variable 'number' is an int. That means "cin >> number" will extract one numeric value from stdin and assign it to 'number'. Then you enter the loop ...
Feb 20 '09 #6
ahh.okay.get it.

i just remembered that when i asked my lecturer if i should put brace for the if statement, and she said i should.

it's confusing now.is the brace necessary?

and regarding entering multiple numbers,i dont quite get it.could you please explain it using an example?
Feb 20 '09 #7
Well, you put the brackets {} in the if statement if you want, but is recommended (even in a book I read) because:
A) it is more organized and easier to read 'cause you know that what's inside the brackets are in the IF statement if you don't remember.

if (this == this)
{
cout << blah;
}
else
{
blah;
}

B) C/C++'s functions are coded with brackets, so it make easy to identify block of code even for a novice that is reviewing your code for the first time.

C) It separates blocks of code that are part of the IF statement from those that are not. Example:

Messy:

If (this==this)
cout << blah1;
blah2 = blah1;

Organized:

If (this== this)
{
cout << blah1;
}
blah2 = blah1;

+(This is my personal opinion) It may even make things easier for the compiler since there is less chance that compilerA will not be confused identifying blocks of codes (like in the messy example) and also compilerB (if you have to use another one) will not be confused either even if it makes programs differently.
++I'll post another reply if I find an answer to the problem in your code. I hope this helps.
Feb 20 '09 #8
#include <iostream.h>
#include <conio.h>

int main ()
{
int number,even = 0,odd = 0,small,big;



cout << "\nInput an integer, one at a time, and press enter.\n";
cout << "Enter the numbers as many as you want.\n";
cout << "Enter integer 0 to stop.\n";
cout << "Enter number: \n";
cin >> number; //this is where your problem lies. You are only asking for a value once. To do it multiple times I recomend wrapping cin within a loop. Sorry I can't tell which one is better because you are the one who knows how developed the program must be and this is your assignment.

small = number;
big = number;

while (number != 0) //Are you sure this loop ends somewhere?
{
number == 0; //looks like an ugly never ending loop to me.
{
if ((number % 2) == 0)
even = even + 1;
else
odd = odd + 1;

if (number < small)
number = small;
else
{
if (number > big)
big = number;
else
endl;
}

}

}

cout << "\nThe biggest number is " << big << endl;
cout << "\nThe smallest number is " << small << endl;

cout << "\nThere is " << even << " even numbers." << endl;
cout << "\nThere is " << odd << " odd numbers." << endl;

getch ();
return 0;

}

Check the comments in bold I put in the code for hints as to what you might want to consider doing to solve the problem (I also put a comment on what it looked like a concerning block). I didn't post comments on all syntax errors (there was another one) nor I fixed the code for you cause I'm only helping, but you are the one who needs to do it so you learn is for your own good). :)
Feb 20 '09 #9
thank you for the responds.

you help me a lot.

thank you again. ^_____^
Feb 21 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: MSM | last post by:
Hello, This may be posted twice if so i apologize. I am creating a form using php where the information entered into the form will go into a database. When creating the tables in SQL where do I...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
6
by: Jax | last post by:
I have Visual Studio 2002 Standard Edition. It has been working fine up to a point and now i'm at that point. Due to the limitations of the edition i am not using any of my own .dll's and instead...
0
by: clemrock | last post by:
Help w/ errors.add_to_base between controller and model Hello, I'm having trouble in routing some errors between model and controller. The errors produced in the controller...
3
by: Milagro | last post by:
Hello Everyone, I'm trying to debug someone elses php code. I'm actually a Perl programmer, with OO experience, but not in php. The code is supposed to upload a photo from a form and save it...
3
by: Learner | last post by:
Hello, I recently converted a VS 2003 application to VS 2005. When I compile it in VS 2005 every thing gets compiled with no errors. But when I try publishing the website I get all different...
4
by: Damodhar | last post by:
Any one help me to parse the bellow xml feed please .. =========================================================== <item> <title>Green earthquake alert Japan(M=6.8) potentially affecting 4.6...
11
by: tracy | last post by:
Hi, I really need help. I run this script and error message appeal as below: drop trigger log_errors_trig; drop trigger log_errors_trig ERROR at line 1: ORA04080: trigger 'LOG_ERRORS-TRIG'...
9
by: beet | last post by:
Hi, I am really not good at c/c++. Some simple code.. #include <stdio.h> #include <stdlib.h> #include <math.h> #include "simlibdefs.h"
11
by: A.C. | last post by:
hi i m declaring a structure globally & there is func1 & main. i m assigning the value to variable(this is a pointer) of structure in fun1 & want to print it in main. this is same kind of...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.