WHY WONT THIS COMPILE?? HELLPP!!

closed account (28CDSL3A)
// Program Description: Your aunt runs a business selling knives.
// She hires door-to-door salespeople in her
// business and has created a system of pay to
// give the salespeople great incentives for
// excellent performance. Your aunt has asked
// you to write a program that asks the salesperson
// how many knives they sold for the month and
// prints out how much he gets paid for the month.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <stdio.h>

int main(void)
{

  int knives_sold = 0;

  printf("How many knives did you sell this month?\n");
  scanf("%d", &knives_sold);


if ( knives_sold<= 100 )
   printf("You have earned $%d from this month's sales\n", knives_sold*5);

else(knives_sold>=101 || knives_sold<= 200);
     int earnings=0;
     earnings= (((knives_sold-100)*10)+500);
     printf("You have earned $%d from this month's sales\n", earnings);
      
else(knives_sold>200};
     int earnings_2=(2000+((knives_sold-200)*15))
     printf("You have earned $%d from this month's sales\n", earnings_2);
     
system("PAUSE");
return 0;
}

ERROR: SYNTAX ERROR BEFORE ELSE
Last edited on
First use the code brackets. Second you have some extra semi collins after your else and else-if. Use curly braces "{}"
closed account (28CDSL3A)
could you show me where to put them? I have been working on this for over three hours and cant figure it out
code tags?...

// Program Written on: 92/15/2010 ...wtf?^.-...
Last edited on
closed account (28CDSL3A)
should be 02.. don't mind that im just interested in compiling and running the program tonight. Is it ok to have two else statements or should there only be one?
don“t get me wrong, but is it sooo hard to use code tags?... im sorry for the wrong linke i posted before ^^ http://cplusplus.com/forum/articles/1295/
Last edited on
closed account (28CDSL3A)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <stdio.h>

int main(void)
{

int knives_sold = 0;

printf("How many knives did you sell this month?\n");
scanf("%d", &knives_sold);


if ( knives_sold<= 100 )
printf("You have earned $%d from this month's sales\n", knives_sold*5);

else(knives_sold>=101 || knives_sold<= 200);
int earnings=0;
earnings= (((knives_sold-100)*10)+500);
printf("You have earned $%d from this month's sales\n", earnings);

else(knives_sold>200};
int earnings_2=(2000+((knives_sold-200)*15))
printf("You have earned $%d from this month's sales\n", earnings_2);

system("PAUSE");
return 0;
}
Well for your first if it should look something like this:
1
2
3
4
if ( knives_sold<= 100 )
{
     printf("You have earned $%d from this month's sales\n", knives_sold*5);
}


Put curly braces after each of your if's and else's. This will get rid of the problem. Oh and get rid of the semicollins after your ifs and elses
closed account (28CDSL3A)
only after?
After each if and else you need them yeah. For more information check out this link: http://cplusplus.com/doc/tutorial/control/
closed account (28CDSL3A)
i will check it out now :) thank you.
If I erase the second else statement, it compiles and runs fine, but when i add it it just doesn't compile.
closed account (28CDSL3A)
I changed it to this, but still doesn't compile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <stdio.h>

int main(void)
{

  int knives_sold = 0;

  printf("How many knives did you sell this month?\n");
  scanf("%d", &knives_sold);


if ( knives_sold<= 100 )
   {
   printf("You have earned $%d from this month's sales\n", knives_sold*5);
   }
else if(knives_sold>=101 || knives_sold<= 200)
     {     
     int earnings;
     earnings= (((knives_sold-100)*10)+500);
     printf("You have earned $%d from this month's sales\n", earnings);
     } 
else(knives_sold>200)
    {
    int earnings_2=(2000+((knives_sold-200)*15))
    printf("You have earned $%d from this month's sales\n", earnings_2);
    }
system("PAUSE");
return 0;
}


ERROR: syntax error in line 35 and before printf in line 37

:'( this is so frustrating
Last edited on
closed account (28CDSL3A)
lines 23 and 25
closed account (28CDSL3A)
thank you everybody I figured it out with your help I am extremely THANKFUL :)
Next time don't post your question on 3 different forums
Topic archived. No new replies allowed.