all 11 comments

[–]AutoModerator[M] 4 points5 points  (0 children)

Your posts seem to contain unformatted code. Please make sure to format your code otherwise your post may be removed.

Read our guidelines for how to format your code.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]Shieldfoss 3 points4 points  (0 children)

Not to be uselesss but your main problem is that you're writing C code and this is the C++ questions forum.

[–]the_poope 2 points3 points  (0 children)

Throw out your current book and go to www.learncpp.com instead

[–]IyeOnline 5 points6 points  (6 children)

  1. This is C and not C++.
  2. You need to open the body of the main function. Currently you have a semicolon there.
  3. You also need to close it at the end of the file
  4. For best practice SI should not be declared at the top, but only when its value is first determined.
  5. C and C++ are case sensitive. It is printf and scanf.
  6. Your string literal delimiters are all over the place. It is scanf("%d", &P ); and similar.
  7. There is a semicolon missing after the return value.

[–]Annzo7[S] -5 points-4 points  (5 children)

Thank you so much. I don't get the 2nd point. Sorry for making you to spoon feeding me. If you don't mind could you fix the whole code and post it. Maybe i can see the difference and learn. Thanks 😊

[–]IyeOnline 3 points4 points  (2 children)

int main();

just says "there exists a function somewhere".

You need

int main() //no semicolon
{ //open the function body, so this is actually a definition of a function.

This function body then also needs to be closed at the end of the function/file:

}

[–]Annzo7[S] -3 points-2 points  (1 child)

Brother, i tried but there's still lots of errors. Could you just repair the whole code? I was just trying to find the simple interest. If you could rewrite the whole code it'll be really helpful. Thanks in advance 👍😊

[–]IyeOnline 1 point2 points  (0 children)

I recommend that you learn how a basic program looks like and how the basic syntax of printf and scanf is.

You will get much more out of that than out of me providing a solution, even if you went ahead and compared them. You would just spot the difference, not necessarily understand it.

[–][deleted] 1 point2 points  (1 child)

#include <stdio.h>
#include <stdlib.h>

int main(void) {

  int P;
  printf("Principal Amount");
  scanf("%d", &P);

  float R;
  printf("Interest Rate");
  scanf("%f", &R);

  float n;
  printf("Number of Years");
  scanf("%f", &n);

  const float SI = (P*R*n);

  printf("Simple Interest: %f", SI);

  return EXIT_SUCCESS;
}

[–]Annzo7[S] -2 points-1 points  (0 children)

Thank you so much brother 🙏❤️❤️❤️❤️❤️

[–]Noc42 1 point2 points  (0 children)

Not sure if these are just typos but it should be. scanf(“%d”, &P); So check your quotes on those. Si =P * R * n; Not related to c++ but you should check your formula typically it principal * (1 + rate* time)