tydog98
|
  |
| Joined: 15 Sep 2009 |
| Total Posts: 27704 |
|
|
| 08 Aug 2012 08:10 PM |
if(sum >= 25); { printf("Thats a big number!"); } else if(sum <= 25); { printf("That's a small number"); } getchar(); }
It says the error is before 'else', but I can't find it
-The king of kings- |
|
|
| Report Abuse |
|
|
L2000
|
  |
| Joined: 03 Apr 2008 |
| Total Posts: 77448 |
|
|
| 08 Aug 2012 08:13 PM |
I don't know much about C; however, judging based on C++, your error may be:
if (sum >= 25); {
Try removing the semicolon from the end of that? |
|
|
| Report Abuse |
|
|
swmaniac
|
  |
| Joined: 28 Jun 2008 |
| Total Posts: 15773 |
|
|
| 08 Aug 2012 08:16 PM |
if(sum >= 25)
No semicolon at the end of an if conditional. |
|
|
| Report Abuse |
|
|
tydog98
|
  |
| Joined: 15 Sep 2009 |
| Total Posts: 27704 |
|
|
| 08 Aug 2012 08:16 PM |
Thank you, I'm new to C
-The king of kings- |
|
|
| Report Abuse |
|
|
tydog98
|
  |
| Joined: 15 Sep 2009 |
| Total Posts: 27704 |
|
|
| 08 Aug 2012 08:21 PM |
Now when I enter my first number into the program, it crashes. Any help there?
-The king of kings- |
|
|
| Report Abuse |
|
|
swmaniac
|
  |
| Joined: 28 Jun 2008 |
| Total Posts: 15773 |
|
| |
|
tydog98
|
  |
| Joined: 15 Sep 2009 |
| Total Posts: 27704 |
|
|
| 08 Aug 2012 08:24 PM |
int main() { int *num1; int *num2; int sum; printf("Enter your numbers: "); scanf("%d", num1); scanf("%d", num2); sum = *num1 + *num2; if(sum >= 25){ printf("Thats a big number!"); } else if(sum <= 25){ printf("That's a small number"); } getchar(); getchar(); }
-The king of kings- |
|
|
| Report Abuse |
|
|
swmaniac
|
  |
| Joined: 28 Jun 2008 |
| Total Posts: 15773 |
|
|
| 08 Aug 2012 08:30 PM |
You're not using scanf correctly. (I'm assuming you included stdio.h)
Those pointers have no (predictable) value, you're instructing the computer to set the memory at that value (which could be anything, including something outside your program's memory space).
Obviously that's not what you want.
int sum, num1, num2;
scanf("%d", &num1); scanf("%d", &num2);
sum = num1 + num2; |
|
|
| Report Abuse |
|
|
swmaniac
|
  |
| Joined: 28 Jun 2008 |
| Total Posts: 15773 |
|
|
| 08 Aug 2012 08:31 PM |
| That said, I'm a newbie to C so this is only my best guess at what's wrong. |
|
|
| Report Abuse |
|
|
tydog98
|
  |
| Joined: 15 Sep 2009 |
| Total Posts: 27704 |
|
|
| 08 Aug 2012 08:35 PM |
Thank you ;>
-The king of kings- |
|
|
| Report Abuse |
|
|