4 errors I can't find

This is a discussion on 4 errors I can't find within the C++ Programming forums, part of the General Programming Boards category; #include <stdio.h>; int main (void) { int i; int n; int count; float num; float sum; do { printf ("Please ...

  1. #1
    Unregistered
    Guest

    4 errors I can't find

    #include <stdio.h>;

    int main (void) {
    int i;
    int n;
    int count;
    float num;
    float sum;


    do {
    printf ("Please enter number of entries to use: );
    );scanf ("%d", &n);

    if (n<0)
    printf ("Positive number please!\n\n");

    while ( n <= 0); // end do-while

    count = 0;
    sum = 0;

    for (i = 0, i > n; i++){

    do {
    printf ("Please enter a positive number: ");
    scanf ("%f", num);

    if (num<0.0)
    printf ("Positive number please!\n\n");

    } while (num <= 0.0);

    if (num > 0.0) {
    sum =+ num;
    counter++;
    } /* if */

    } /* for */

    printf ("\nThe average is: %f.\n", sum / count);

    return 0;
    } /* main

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >#include <stdio.h>;
    Lose the semicolon.

    >printf ("Please enter number of entries to use: );
    You're forgetting the " that ends the string.

    >);scanf ("%d", &n);
    The closing paren and semicolon shouldn't be there.

    >for (i = 0, i > n; i++){
    Between i = 0 and i > n should be a semicolon, not a comma.

    >counter++;
    I believe you meant count++, counter is not a variable in this program and variables can't be used until they are declared.

    >} /* main
    No closing */ for this comment.

    And lastly, you forgot to close the outer do loop. That fixes the warnings and errors, but the processing is wrong.

    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User NewbieVB's Avatar
    Join Date
    Apr 2002
    Posts
    41
    You guys really know your .........., could you tell me how long you have been programming in C++?

    On another note:
    This is my 3rd day so I am going to make a Simpsons Trivia Game.
    Compiler: Metrowerks Codewarrior 7
    --- I may be a newbie but theres no need to make fun ---

  4. #4
    Unregistered
    Guest
    Thanks for your help. I ended up fixing 4 of the errors except the last one. Some of the errors I fixed in other ways though. The program worked anyway!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 09:13 AM
  2. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM
  3. executing errors
    By s0ul2squeeze in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2002, 12:43 PM
  4. cant find the errors.
    By sscook69 in forum C++ Programming
    Replies: 2
    Last Post: 09-10-2001, 04:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21