-6

I am trying to learn programming. It is a simple question but I can't solve it. Why am I getting an error? What's wrong? How can I solve this problem? Please help me.

Here is problem definition and my code:

enter image description here

#include<stdio.h>

void calculateCharged(int c) {
    int a;
    int hours = scanf("%d", &a);
    int totalFee = 25;
}

int main(void) {

    int i;
    int b;
    printf("Please Enter Number of Cars ");
    scanf("%d", &i);
    for (b = 0; b < i; b++) {
        calculateCharged(hours)
        if (hours)<8
        totalFee += hours * 0, 5
        else if hours < 24
        int additionalHours = hours - 7
        totalFee += additionalHours * 5
        totalFee += hours * 0, 5
        else
        int days = hours / 24
        int extraHours = hours % 24
        totalFee += days * 50
        totalFee += days * 24 * 0, 5
        totalFee += extraHours * 5
        totalFee += extraHours * 0, 5
    }
}
Olcay Ertaş
  • 5,987
  • 8
  • 76
  • 112
Mert
  • 3
  • 3
  • 1
    No image and C/C++ tagging please. Please read [how to ask](http://stackoverflow.com/help/how-to-ask). – Mohit Jain Mar 08 '17 at 10:11
  • 4
    There's millions of errors here, you should pick up a book on C, guessing's not the way. – George Mar 08 '17 at 10:11
  • 2
    You get errors because you haven't learned the language yet. [Please find a good beginners book](http://stackoverflow.com/questions/562303/the-definitive-c-book-guide-and-list) to read, and start over with something simpler. – Some programmer dude Mar 08 '17 at 10:11
  • Mert, aradığın cevabı bulduysan cevaplardan birini kabul etmelisin. Sorunun puanının altındaki yeşil tik işaretine tıklayarak yapabilirsin bunu. – Olcay Ertaş Jun 02 '17 at 07:17

2 Answers2

4

The solution is literally in the error message.

In C, the syntax of the if requires the parentheses around the condition.

So it should be

else if(hours < 24)

It's a good hint that your first if was accepted.

Also you need braces around your scopes, your code looks like un-indented Python or something. Please read some basic reference material before trying to use a new programming language.

unwind
  • 391,730
  • 64
  • 469
  • 606
0

I didn't read your problem definition but your code sould be at least like this to be correct as syntax and logic:

#include<stdio.h>

float totalFee = 0;
int hours = 0;

int main(void) {

    int i;
    int b;
    printf("Please Enter Number of Cars ");
    scanf("%d", &i);

    for (b = 0; b < i; b++) {
        scanf("%d", &hours);
        if (hours < 8) {
            totalFee += hours * 0.5;
        } else if (hours < 24) {
            float additionalHours = hours - 7;
            totalFee += additionalHours * 5;
            totalFee += hours * 0.5;
        } else {
            float days = hours / 24;
            float extraHours = hours % 24;
            totalFee += days * 50;
            totalFee += days * 24 * 0.5;
            totalFee += extraHours * 5;
            totalFee += extraHours * 0.5;
        }
    }
}
Olcay Ertaş
  • 5,987
  • 8
  • 76
  • 112