Thread: Need help with some errors on my Hw

  1. #1
    Registered User
    Join Date
    Feb 2016
    Posts
    5

    Need help with some errors on my Hw

    Hello I am getting a few errors that I cannot get rid of. My program assignment is:
    // gets an integer from the user and returns it
    int GetInt(void);


    // gets a double from the user and returns it
    double GetDouble(void);
    // gets a letter from the user and returns it
    char GetInitial(void);
    // takes two arguments, an integer and a double

    // adds 10 to the integer and returns the result
    //multiplies the double argument by .5 and prints the result onto the screen
    int FunctionOne( int arg1, double arg2);


    // takes one character argument and returns and integer

    //change the letter to uppercase (use ctype.h)
    //return a 1 if the letter is in the first half of the alphabet(A-M)
    //return a 2 if the letter is in the second half of the alphabet (N-Z)
    int FunctionTwo(char arg1);

    Main function logic:
    declare variables
    call GetInt, GetDouble, and GetInitial
    pass the inputs to FunctionOne and FunctionTwo

    print the integer with the 10 added to it
    print a 1 or a 2 based on the initial that was entered




    Code:
    //Jason Swisher
    // September 26
    // Lab 2
    
    
    
    
    #define _CRT_SECURE_NO_WARNINGS
    #include <stdio.h>
    #include <ctype.h>//toupper, tolower,
    
    
    int GetInt(void);
    
    
    double GetDouble(void);
    
    
    char GetInitial(void);
    
    
    int FunctionOne(int Top, double dbl1);
    
    
    int FunctionTwo(char Rew);
    
    
    int main()
    {
        int GetInt(void);
    
    
        double GetDouble();
    
    
        char GetInitial();
    
    
        int FunctionOne(int Top, double dbl1);
    
    
        int FunctionTwo(char Rew);
    
    
        return 0;
    }
    
    
    int GetInt(void)
    {
        int Top;
        printf("Pease enter an integer/n");
        scanf("%d", &Top);
        printf("Your integer is %d /n", Top);
        return Top;
    
    
    }
    
    
    double GetDouble(void)
    {
        double dbl1;
        printf("Please enter a double/n");
        scanf("%lf", &dbl1);
        printf("Your double is %f", dbl1);
        return dbl1;
    }
    
    
    char GetInital(void)
    {
        char Rew;
        printf("Please enter an intial/n");
        scanf(" %c", &Rew);
        prinft("Your intial is  %c /n", Rew);
        return Rew;
    }
    
    
    int FunctionOne(int Top, double dbl1)
    {
        Top = Top + 10;
        printf("Your integer plus 10 is %d/n", Top);
        dbl1 = dbl1 / 2;
        printf("Your double divided by 2 is %f/n", dbl1);
        return Top, dbl1;
    }
    
    
        int FunctionTwo(char Rew)
    {
        Rew = toupper(Rew);
        if(Rew >='M')
    {
        printf("1");
    }
        else Rew;
    { printf("2");
    }
        return 0;
    
    
    }

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Well, your program has several problems, some caught by the compiler, and some that aren't.
    The output of the compiler is:
    Code:
    mingw32-gcc.exe -Wall -pedantic -Wextra -Wall -std=c99 -g  -c C:\Users\jk\Desktop\jswisher\main.c -o obj\Debug\main.o
    C:\Users\jk\Desktop\jswisher\main.c: In function 'GetInital':
    C:\Users\jk\Desktop\jswisher\main.c:76:5: warning: implicit declaration of function 'prinft' [-Wimplicit-function-declaration]
         prinft("Your intial is  %c /n", Rew);
         ^
    C:\Users\jk\Desktop\jswisher\main.c: In function 'FunctionOne':
    C:\Users\jk\Desktop\jswisher\main.c:87:15: warning: left-hand operand of comma expression has no effect [-Wunused-value]
         return Top, dbl1;
                   ^
    C:\Users\jk\Desktop\jswisher\main.c: In function 'FunctionTwo':
    C:\Users\jk\Desktop\jswisher\main.c:98:10: warning: statement with no effect [-Wunused-value]
         else Rew;
              ^
    The obvious mistakes are the misspellings of "printf", "Initial", and '\n' which you need to correct. Statements with no effect need to be erased or reworked. Like, you cannot return more than one thing from a function, ever.

    As for the rest of the code in main(), there is a difference between what calling a function should look like, and what declaring a function should look like. Your lines in main() essentially declare these functions again, for no useful effect.

    I would expect, given that some of these functions take arguments, you are supposed to come up with this:
    Code:
    int main(void)
    {
       int wholen = 0;
       double realn = 0;
       char initial = '\0';
       wholen = GetInt();
       realn = GetDouble();
       initial = GetInitial();
       FunctionOne(wholen, realn); // This function should be changed so that it doesn't return anything (i.e. void FunctionOne)
       FunctionTwo(initial); // This function should be changed so that it doesn't return anything (i.e. void FunctionTwo)
       return 0;
    }
    Take a careful look at the differences in this code. Notice that in main the arguments sent to FunctionOne and FunctionTwo correspond to variable names in the main function. In the cases of the functions GetInt, GetInitial, and GetDouble, the function is actually supposed to retrieve some information from the user and send it back, through the return statement, to be stored in a variable inside main. The whole reason the program might work is because main sends in copies of its variables for FunctionOne and FunctionTwo to modify and display to the user.

    And you can see in my comments that I ask for some changes. The reasons for this suggestion are:
    1) It appears that the functions are called and then the program will end, meaning that the changes don't need to be kept
    2) If you wanted to keep the changes, especially if you wanted to call the functions again with the new values, you would need to use structs or pointers to succeed, and I'm guessing you haven't learned those yet.
    Last edited by whiteflags; 09-26-2016 at 04:28 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. i m getting some errors
    By prdeepss in forum C Programming
    Replies: 3
    Last Post: 03-11-2009, 02:49 AM
  2. HELP with DX9 Errors!!!
    By Tommaso in forum Game Programming
    Replies: 7
    Last Post: 06-28-2006, 02:51 PM
  3. errors
    By sentienttoaster in forum C++ Programming
    Replies: 1
    Last Post: 11-17-2003, 08:55 AM
  4. errors.. errrors.. more errors
    By Klinerr1 in forum C++ Programming
    Replies: 17
    Last Post: 07-23-2002, 08:43 PM
  5. Dev and errors
    By Moffesto in forum C++ Programming
    Replies: 0
    Last Post: 06-22-2002, 12:17 AM

Tags for this Thread