Thread: program help cannot figure out why I am getting a freaking error

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    24

    program help cannot figure out why I am getting a freaking error

    Can anyone tell me why I am getting an error
    Code:
    // isbnreader123.cpp : main project file.
    
    #include "stdafx.h"   //visual studio
    #include <stdio.h>    // printf scanf
    #include <ctype.h>    // tolower
    #include <string.h>   // strlen
    #include <stdlib.h>   // isdigit atoi
    #include <process.h>   // system()
    
    void hello(void);  //program to welcome user
    char is_valid (char vaild_y_n); // checks for yes or no to continue program
    int is_valid_isbn (char isbn[]); //function to check for non numeric input within ISBN
    int check_digit_calc(void);  //calculates check digit
    
    char isbn[13]; //array for ISBN (character string)
    int isbn_num[13];  //array for ISBN (numeric)
    
    int main()
    {
        char y_n = 'y'; //sentinel
        int i, chk_valid, last_digit; // i=for counter, chk_vaild= switch, last dig= calculated last isbn digit
    
        hello(); //function call
    
        while(y_n =='y')
        {
            printf("\n\n Please enter you ISBN number");
            scanf("%s",isbn); //reads isbn into character string isbm[] 
            chk_valid = is_valid_isbn(isbn); //calls function to check for valid isbn
            if(chk_valid==1)
            {
                last_digit = check_digit_calc(); //recives calculated last digit
    
                    if(isbn_num[9]==last_digit)
                        printf(" \n\n The ISBN is valid\n\n");
                    else
                        printf("\n\n You have entered an invalid ISBN \n\n");
            }
            else
                printf("\n\n The ISBN you have entered contained non-numeric characters!\n\n");
            printf("Do you wish to enter another ISBN number ?");
            scanf("%c",&y_n);
            y_n=is_valid(y_n);      //checks is user wants to continue
            system("cls");
             }
             return 0;
             }
             void hello(void)              //function to greet user
             {
                     printf("\n *** Welcom to the ISBN check digit program where you enter and ISBN and we check it *****\n");
                     printf("\n ****How cool is that\a\..........**\n");
                     printf("\n **** Save your applause for after ****\n");
             }
             char is_valid(char valid_y_n)
             {
                 valid_y_n = tolower(valid_y_n);
                 while(valid_y_n != 'y'&& valid_y_n != 'n')
                 {
                     printf("You can only enter 'y' or 'n'");
                     scanf("%c",&valid_y_n);
                     valid_y_n = tolower(valid_y_n);
                 }
                 return (valid_y_n);
             
             int is_valid_isbn(char isbn[])
             {
                 int i,  //counter loop
                     j=0, //index for array
                     invalid=1 ;
                 char isbn_num1[1]; //singal digit string for atoi
                 char *ptr_num1;    // pointer for atoi
    
                 ptr_num1 = &isbn_num1[0]; //initialization of pointer for atoi
                 for (i = 0; i<strlen(isbn);i++) //loop to contiune to the end of the string
                 {
                     if(isbn[i] != '-') //gets rid of the hyphens and ignores them
                     {
                         if(isdigit(isbn[i]) == 0)        //fail
                             invalid = 0;        //switch for main()
                         else
                         {
                             isbn_num1[0] = isbn[i]; //stores characters as a string
                             isbn_num[j] = atoi(ptr_num1); // stores characters in a form atoi() can use
                             j++;
                         }
                     }
                 }
                 return(invalid);
    
                 int check_digit_calc(void)    //calculates check digit
                 {
                     int k, digit_total = 0,
                     digit_value = 0;
    
                     for( k = 0; k < 9; k++)
                         digit_total += (k+1)* isbn_num[k];
                     digit_value = digit_total % 11;
                     return (digit_value);
                 }

  2. #2
    Registered User TheBigH's Avatar
    Join Date
    May 2010
    Location
    Melbourne, Australia
    Posts
    426
    You have to close your functions with a } after the return statement.
    Code:
    while(!asleep) {
       sheep++;
    }

  3. #3
    Registered User
    Join Date
    Oct 2011
    Posts
    24
    Yeah well I just did that and here is the error I get now
    >------ Build started: Project: isbnreader123, Configuration: Debug Win32 ------
    1>Compiling...
    1>isbnreader123.cpp
    1>.\isbnreader123.cpp(28) : warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
    1> C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\stdio.h(306) : see declaration of 'scanf'
    1>.\isbnreader123.cpp(42) : warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
    1> C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\stdio.h(306) : see declaration of 'scanf'
    1>.\isbnreader123.cpp(21) : warning C4101: 'i' : unreferenced local variable
    1>.\isbnreader123.cpp(60) : warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
    1> C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\stdio.h(306) : see declaration of 'scanf'
    1>.\isbnreader123.cpp(74) : warning C4018: '<' : signed/unsigned mismatch
    1>.\isbnreader123.cpp(91) : error C2601: 'check_digit_calc' : local function definitions are illegal
    1> .\isbnreader123.cpp(66): this line contains a '{' which has not yet been matched
    1>.\isbnreader123.cpp(105) : fatal error C1075: end of file found before the left brace '{' at '.\isbnreader123.cpp(66)' was matched
    1>Build log was saved at "file://c:\Users\Dustin\Documents\Visual Studio 2008\Projects\isbnreader123\isbnreader123\Debug\Bu ildLog.htm"
    1>isbnreader123 - 2 error(s), 5 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

  4. #4
    Registered User
    Join Date
    Oct 2011
    Posts
    24
    Nevermind I am retarded I figured it out god I am tired.... now if anyone has any suggestions on my other post please help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Error that I can't figure out.
    By mytrademark in forum C Programming
    Replies: 3
    Last Post: 10-03-2011, 06:54 PM
  2. Odd bus error, can't figure it out.
    By Subsonics in forum C Programming
    Replies: 15
    Last Post: 11-05-2009, 11:44 AM
  3. Program Error That I cant figure out
    By Toonzaka22 in forum C++ Programming
    Replies: 0
    Last Post: 09-27-2009, 09:14 PM
  4. program is freaking out on me
    By Rubiks14 in forum C++ Programming
    Replies: 2
    Last Post: 12-04-2005, 01:07 PM
  5. stupid recurring freaking error bah!
    By Leeman_s in forum C++ Programming
    Replies: 2
    Last Post: 09-07-2002, 02:04 PM