473,569 Members | 2,457 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

suggest parentheses around assignment used as truth value

1 New Member
the errors come up as suggest parentheses around assignment used as truth value which it says for the lines 7,10,13,16,19 and im just wondering what it is that is wrong with it if anyone could let me know cause im new to this. heres my code:

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3.     int main(int argc,char*argv[]){
  4.     int integer;
  5.     printf("please enter an integer \n");
  6.     scanf("%d", &integer);
  7.     if (integer=(1)){
  8.     printf ("you entered: \n one");
  9. }
  10.     if (integer=(2)){;
  11.     printf ("you entered: \n two");
  12. }
  13.     if (integer=(3)){;
  14.     printf ("you entered: \n three");
  15. }
  16.     if (integer=(4)){;
  17.     printf ("you entered: \n four");
  18. }
  19.     if (integer=(5)){;
  20.     printf ("you entered: \n five");
  21. }
  22.     if (integer<1){;
  23.     printf ("you entered a number less then one\n");
  24. }
  25.     if (integer>5){;
  26.     printf ("you entered a number greater than five");
  27. }
  28.     return 0;
  29. }
  30.  
  31.  
the lines 7, 10, 13, 16 19 are the ones with the "integer=number " part
Mar 17 '13 #1
1 4406
weaknessforcats
9,208 Recognized Expert Moderator Expert
This code:
Expand|Select|Wrap|Line Numbers
  1.  if (integer=(1)){
  2. etc...
should be:
Expand|Select|Wrap|Line Numbers
  1.  if (integer == 1){
  2. etc...
The = may mean "equals" in mathematics but in C and C++ it means "assignment ". The original code would try to change the integer entered to 1 instead of testng it for 1.

Note that if (integer=(1)) will always be true since 1 is true. That means the code following it can never be reached and that is what the compiler is frowning about.
Mar 17 '13 #2

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

Similar topics

2
1983
by: peter | last post by:
I've got a table which is used for storing votes, each row has a field with a reference to the user who's been voted for and i'd like to simply get the user ref with the most votes,or if tied, return both of them. I cant use subqueries as it's a mysql 4.0 server, any ideas on how i could do it (without retrieving all the nominees then doing...
1
1209
by: antonyliu2002 | last post by:
Suppose that I have the following on my web: Your annual income: o > o < ___________ If the user enters a number in the textbox indicated by the underline, but forget to click either of the two radio buttons for ">" and "<", I want to warn the user that if he does supply a (valid) number for the annual income information, he must...
90
3390
by: John Salerno | last post by:
I'm a little confused. Why doesn't s evaluate to True in the first part, but it does in the second? Is the first statement something different? False print 'hi' hi Thanks.
18
15108
by: lovecreatesbea... | last post by:
Isn't code at line 2 correct? a.c:2: warning: suggest parentheses around && within || int isleap(int year){ if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) /*line 2*/ return 1; return 0; }
6
17098
by: natkw1 | last post by:
Hi all, I'm new to C and kind of confused on this. I've had a look around this group for suggestions but still not sure why the warning is occurring. What I've done is this <code snip> void foo(char loc) {
3
2544
by: Lyn | last post by:
Can anyone explain this for me? A sub procedure can be called with or without parentheses around the arguments. By personal convention, I normally use parentheses. I am in the middle of a fairly large project (for me), happily using parentheses everywhere -- until this happened: The following sub is defined in a class module. Public...
6
9095
by: billelev | last post by:
This is probably very easy, but I can't see how you would do this... I have a table that is used as a source table for a report. The table contains percentage values. In the report, I would like to display percentage values less than zero with parentheses around them. I can change the color, format etc. but I'm not sure how you would enclose...
0
7618
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7926
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8132
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7678
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5222
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3656
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2116
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
944
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.