By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,471 Members | 722 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,471 IT Pros & Developers. It's quick & easy.

I'm getting an Expression Syntax error and I can't figure out what's wrong.... :(

P: 4
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3.    void displayInformation(void);
  4.     int getInformation(int);
  5.  
  6.    int main(void)
  7.  
  8.        {
  9.            int small;       
  10.  
  11.          displayInformation();
  12.  
  13.          getInformation(int);     
  14.  
  15.  
  16.           return 0;
  17.        }
  18.  
  19.  
  20.     void displayInformation(void)
  21.  
  22.        {
  23.               printf("Welcome to the Squared Cube!\n");
  24.               printf("Today we are going to be showing you numbers,\n");
  25.           printf("their square and their cube.\n\n");
  26.  
  27.           printf("What you will need to do is: \n");
  28.           printf("Enter two numbers below.\n");
  29.             printf("The second number must be higher than the lower number.\n\n");
  30.  
  31.           printf("Please enter your two numbers below.\n");
  32.  
  33.  
  34.        }
  35.  
  36.  
  37.     int getInformation(int)
  38.  
  39.         {
  40.             int small;
  41.  
  42.             scanf("%d", &small);
  43.  
  44.             printf("The small number you chose was &d.", small);
  45.  
  46.  
  47.         }
  48.  
Nov 8 '10 #1

✓ answered by Oralloy

It looks like you have a syntax error at line 13, where you invoke getInformation().

Because you declared getInformation() at line 4 as:
Expand|Select|Wrap|Line Numbers
  1.     int getInformation(int); 
You are constrained to pass an integer to the function when you call it.

The code at line 13:
Expand|Select|Wrap|Line Numbers
  1.         getInformation(int);
Has two errors -
  1. it does not pass an int value to getInformation()
  2. it uses the keyword int, where a value expression would normally be written.

So, decide what your function getInformation() is supposed to do, and we can help you set up the correct declaration, invocations, and definition.

Do you want the function to take an integer variable as a parameter, and populate that variable?

Does the function act independently of the rest of your program, simply reading a value and printing it, as it does now?

Should the function do something else?

Let us know, and we'll help you through this.

Good Luck!

Share this Question
Share on Google+
7 Replies


P: 14
In the definition of a function that takes an argument, you have to provide a name (identifier) for the argument as well as its type. And if you want the function to modify the value of that argument, that's the variable it should be working on, and not a local variable (one declared inside the function). So your getInformation should look like this:

Expand|Select|Wrap|Line Numbers
  1.    int getInformation(int input)
  2.  
  3.         {
  4.             scanf("%d", &input);
  5.  
  6.             printf("The small number you chose was %d.\n", input);
  7.         }
  8.  
So I eliminated the declaration of "small" in the body of the function because that would make it a local variable -- one that exists only inside the function.
Also, notice that I didn't call anything "small" inside the function; I used "input" instead, just to make a point. I could have named it "small", but that's not necessary. What's important is that I used the same name throughout the function.


When you call the function from another function (e.g. main), you must provide the name (and NOT the type) of the variable that you want the function to use. So line 13 should be:
Expand|Select|Wrap|Line Numbers
  1.        getInformation(small);      
Nov 8 '10 #2

Oralloy
Expert 100+
P: 983
It looks like you have a syntax error at line 13, where you invoke getInformation().

Because you declared getInformation() at line 4 as:
Expand|Select|Wrap|Line Numbers
  1.     int getInformation(int); 
You are constrained to pass an integer to the function when you call it.

The code at line 13:
Expand|Select|Wrap|Line Numbers
  1.         getInformation(int);
Has two errors -
  1. it does not pass an int value to getInformation()
  2. it uses the keyword int, where a value expression would normally be written.

So, decide what your function getInformation() is supposed to do, and we can help you set up the correct declaration, invocations, and definition.

Do you want the function to take an integer variable as a parameter, and populate that variable?

Does the function act independently of the rest of your program, simply reading a value and printing it, as it does now?

Should the function do something else?

Let us know, and we'll help you through this.

Good Luck!
Nov 8 '10 #3

P: 4
In the end, it is supposed to allow the user to enter two numbers. One being smaller than the other. Then, it is supposed to print a table to the screen with the a list of numbers, the first being the smallest and then counting up to the largest. Printing each integer, their square and their cube.
Nov 9 '10 #4

Oralloy
Expert 100+
P: 983
Mike,

That's a fair answer.

Just remember that we don't do homework problems for people. We'll help with direct questions, but it's your job to actually write the programs, learn the language, and learn the methodology of programming.

So....why don't you put together the next step of your project, and if you have problems that you can't figure out, ask for help.

I would suggest that you write out a sequence of english-like instructions for yourself, and once you've tested them on paper, translate them into C or C++.

Go one step at a time. If you don't try to do everything at once, you won't be overwhelmed with a mass of errors when you try to compile things. Then it should be pretty easy to get your work done.
Nov 9 '10 #5

P: 4
I understand that. I'm not asking for anyone to do any code writing for me. I was only asking about the error.

Now that I have had help with the error, I've straightened out the issue and I am about 95% finished. :)
Nov 9 '10 #6

Oralloy
Expert 100+
P: 983
I'm glad to hear it.

I hope it works.

Luck!
Nov 9 '10 #7

P: 4
Thanks for the input everyone. I got it to work perfectly! Hopefully one day I can post on here as a helper instead of someone seeking help.
Nov 9 '10 #8

Post your reply

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