3 Replies - 366 Views - Last Post: 30 July 2014 - 08:08 AM Rate Topic: -----

#1 Deepak_Patil  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 01-July 14

Addition Program Errors

Posted 29 July 2014 - 12:08 AM

I compiled below program in gcc and got following errors. Would anyone help please to solve them?

[/// Addition program.
#include <stdio.h>

// function main begins program execution
int main(void)
{
    int 45; // first number to be entered by user
    int 72; // second number to be entered by user
    int sum; // variable in which sum will be stored

    printf( "45\n" ); // prompt
    scanf( "%d" , &45 ); //read an integer

    printf( "72\n" ); // prompt
    scanf( "%d" , &72 ); // read an integer

    sum = 45 + 72; // assign total to sum

    printf( "sum is %d\n" , sum ); // print sum
} // end function main


Errors are as below,

mingw32-gcc.exe   -c "G:\CodeBlocks Projects\Adding Two Integers\main.c" -o "G:\CodeBlocks Projects\Adding Two Integers\main.o"
G:\CodeBlocks Projects\Adding Two Integers\main.c: In function 'main':
G:\CodeBlocks Projects\Adding Two Integers\main.c:[b]7:9: error: expected identifier or '(' before numeric constant[/b]
G:\CodeBlocks Projects\Adding Two Integers\main.c:[b]8:9: error: expected identifier or '(' before numeric constant[/b]
G:\CodeBlocks Projects\Adding Two Integers\main.c:[b]12:19: error: lvalue required as unary '&' operand[/b]
G:\CodeBlocks Projects\Adding Two Integers\main.c:[b]15:19: error: lvalue required as unary '&' operand[/b]
Process terminated with status 1 (0 minute(s), 8 second(s))
4 error(s), 0 warning(s) (0 minute(s), 8 second(s))


Is This A Good Question/Topic? 0
  • +

Replies To: Addition Program Errors

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6063
  • View blog
  • Posts: 23,517
  • Joined: 23-August 08

Re: Addition Program Errors

Posted 29 July 2014 - 03:29 AM

You can't use an integer as the first character in the name of a variable: read me.
Was This Post Helpful? 0
  • +
  • -

#3 Deepak_Patil  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 01-July 14

Re: Addition Program Errors

Posted 30 July 2014 - 08:01 AM

View PostJackOfAllTrades, on 29 July 2014 - 03:29 AM, said:

You can't use an integer as the first character in the name of a variable: read me.


Hi,
Would you please elaborate where I have to make changes?
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3480
  • View blog
  • Posts: 11,874
  • Joined: 12-December 12

Re: Addition Program Errors

Posted 30 July 2014 - 08:08 AM

    int 45; // first number to be entered by user

You cannot name a variable 45, or 72.

In particular:
    sum = 45 + 72; // assign total to sum

how would the compiler distinguish between a variable named '45' and the number 45?

An identifier can include a number, but it cannot start with a number.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1