-6

For some reason, my "if" expression will not work in Xcode. It gives a "parse issue" with the if expression. Any suggestions? The error code is: "Expected unqualified-id". I am working with xcode. Please see below:

if (surfaceArea > 750)       

{
totalCost t=50;
}

Thanks in advance,

Issy
  • 1
  • 2
  • 4
    Welcome to Stack Overflow! Please **[edit]** your question with an [mcve] or [SSCCE (Short, Self Contained, Correct Example)](http://sscce.org) – NathanOliver Oct 11 '17 at 13:30
  • 4
    I can't parse it too. Seriously, your comment have leaked to the next line – Eugene Sh. Oct 11 '17 at 13:30
  • 2
    Is the newline in the comment there in the real code too? How about the space in `totalCost t`? Is the code you show a copy-paste of the *actual* code you have? – Some programmer dude Oct 11 '17 at 13:31
  • I am pretty sure XCode has a nice syntax highlighting making these errors obvious to spot.. – Eugene Sh. Oct 11 '17 at 13:34
  • 2
    `totalCost t+=50;` I don't use xcode, but that looks wrong. – 001 Oct 11 '17 at 13:35
  • My apologies, I copy/pasted my code into my comment on this forum and the formatting is wrong. (The comment isn't actually included in the code, as it appears in my question) Excluding the comment all together, any suggestions as to why the 'if expression' would send a parse error?. – Issy Oct 11 '17 at 13:39
  • Without the actual code we can't answer the question. You are using xcode - then copy it right from there. – Eugene Sh. Oct 11 '17 at 13:40
  • Then *edit your question* to include the actual copy-pasted code. – Some programmer dude Oct 11 '17 at 13:43
  • I just modified the code in my question to alleviate the comment confusion/interference. – Issy Oct 11 '17 at 13:45
  • Have you read the comments at all? – Eugene Sh. Oct 11 '17 at 13:46
  • I removed the "+" in the totalCost line and also removed the comments line (Please see new code in my original inquiry). I am still getting the error. The highlighting for the syntax is helpful and that is how I know where my error is, but it does not suggest a "fix" for the error. I know it's a simple mistake, as this is my first programming course and I definitely inexperienced at programming. – Issy Oct 11 '17 at 13:53
  • you need to provide a [mcve]. What is `totalCost` if it is not a type then please [read a book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list), if it is it also cannot hurt – 463035818_is_not_an_ai Oct 11 '17 at 14:00
  • Okay, my question is strictly focused on the line: if (surfaceArea > 750) This line all by itself, without anything else added sends the error mentioned in my inquiry. I have "read a book" and it says to input the if expression just as I have it. I am simply inquiring if Xcode needs something more or different to process an if expression. – Issy Oct 11 '17 at 14:13
  • FYI, you are declaring a variable in the statement block. The variable will disappear when execution leaves the statement block. – Thomas Matthews Oct 11 '17 at 14:16
  • Thank you, Thomas – Issy Oct 11 '17 at 14:22
  • There's nothing wrong with `if (surfaceArea > 750)` as long as `surfaceArea` is defined somewhere. Compilers' error reporting isn't 100% perfect, if it's complaining about that line, there could be a problem with some lines above or below it. For example, `totalCost t=50;` looks wrong. Unless you have `typedef`ed or `#define`d `totalCost` to be something else, that doesn't make sense. If `totalCost` is a variable that you're tying to assign to, you need to do `totalCost=50;` or `totalCost+=50;`. You haven't provided an MCVE so it's tough to tell exactly what the problem is. – yano Oct 11 '17 at 14:31
  • Thank you, that is very helpful – Issy Oct 11 '17 at 14:51
  • Thank you everyone, my issue has been resolved. I had an unneeded additional brace above my code that was blocking the variable "surfaceArea" and the compiler was not recognizing the variable. – Issy Oct 11 '17 at 15:31

2 Answers2

5
if (surfaceArea > 750)       //adding 50 dollars to cost if product is 
//over 750 sq. inches

{
 totalCost t+=50;
}

make a comment line // . Hope you understood.

To write a multi line comment use /* .... */

SaravananKS
  • 577
  • 4
  • 18
  • I do understand and have removed the comment to alleviate the confusion of that. It was a formatting mistake when I copy/pasted the code. I posted too quickly. This is my first post on here. My apologies, but I have edited my original post to reflect my actual code. – Issy Oct 11 '17 at 14:00
1

Just remove over 750 sq. inches from your code. And use /* */ for multiline comments.

Anton Malyshev
  • 8,686
  • 2
  • 27
  • 45
  • Hey, Anton. My apologies for the confusion in regards to my comment lines. I have removed the comment lines to alleviate any confusion this may have caused. With the code as it is now (see original inquiry), any suggestions? I know this has to be an elementary mistake. I am taking my first programming course and am very inexperienced. – Issy Oct 11 '17 at 14:02
  • As stated in comments `totalCost t+=50;` seems to be suspicious as well. What `totalCost t` should be? If it's declaration it probably should be made outside the loop, then just `t+=50;` inside. – Anton Malyshev Oct 11 '17 at 14:05