Can someone check my program?

This is a discussion on Can someone check my program? within the C++ Programming forums, part of the General Programming Boards category; I'm missing something really easy but I can't figure out what. The identifiers are not picking up. Code: #include "stdafx.h" ...

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    9

    Can someone check my program?

    I'm missing something really easy but I can't figure out what.

    The identifiers are not picking up.

    Code:
    #include "stdafx.h"
    #include "stdlib.h"
    #include <iostream>
    #include <cmath>
    #include <iomanip>
    #include <cstdlib>
    #include <ctime>
    
    using namespace std;
    
    int id;
    int age;
    long phone;
    long creditcard;
    
    int main()
    {
    cout << "Please enter Customer ID (0-49): " <<endl;
    
    if (id > 49&& id <0)
    {
    cout << "ERROR: Please enter Customer ID (0-49): " << endl;
    }
    fill_values (age, phone, creditcard);
    securitypreference (security);
    
    if (security == 0)
    {
    print_secure (id, age);
    }
    
    else
    {
    print_all (id, age, phone, creditcard);
    }
    
    }
    
    void fill_values()
    {
    srand(time(0));
    age = (rand() % 40) + 20;
    phone = (rand() % 8999999) + 1000000;
    creditcard = (rand() % 8999) + 1000;
    }
    
    int security_preference()
    {
    srand(time(0));
    security = (rand() % 2);
    return security;
    }
    
    void print_secure(id,age)
    {
    srand(time(0));
    cout << id << endl; 
    cout << age << endl;
    }
    
    void print_all(id, age, phone, creditcard)
    {
    cout << id << endl; 
    cout << age << endl; 
    cout << phone << endl; 
    cout << creditcard << endl; 
    }
    I'm getting the following errors:

    1>c:\users\mike\documents\visual studio 2008\projects\final\final\final.cpp(24) : error C3861: 'fill_values': identifier not found
    1>c:\users\mike\documents\visual studio 2008\projects\final\final\final.cpp(25) : error C2065: 'security' : undeclared identifier
    1>c:\users\mike\documents\visual studio 2008\projects\final\final\final.cpp(25) : error C3861: 'securitypreference': identifier not found
    1>c:\users\mike\documents\visual studio 2008\projects\final\final\final.cpp(27) : error C2065: 'security' : undeclared identifier
    1>c:\users\mike\documents\visual studio 2008\projects\final\final\final.cpp(29) : error C3861: 'print_secure': identifier not found
    1>c:\users\mike\documents\visual studio 2008\projects\final\final\final.cpp(34) : error C3861: 'print_all': identifier not found
    1>c:\users\mike\documents\visual studio 2008\projects\final\final\final.cpp(41) : warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
    1>c:\users\mike\documents\visual studio 2008\projects\final\final\final.cpp(49) : warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
    1>c:\users\mike\documents\visual studio 2008\projects\final\final\final.cpp(50) : error C2065: 'security' : undeclared identifier
    1>c:\users\mike\documents\visual studio 2008\projects\final\final\final.cpp(51) : error C2065: 'security' : undeclared identifier
    1>c:\users\mike\documents\visual studio 2008\projects\final\final\final.cpp(55) : error C2448: 'print_secure' : function-style initializer appears to be a function definition
    1>c:\users\mike\documents\visual studio 2008\projects\final\final\final.cpp(62) : error C2448: 'print_all' : function-style initializer appears to be a function definition
    1>Build log was saved at "file://c:\Users\Mike\Documents\Visual Studio 2008\Projects\Final\Final\Debug\BuildLog.htm"
    1>Final - 10 error(s), 2 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

  2. #2
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,650
    So, sufoode, do you think our OP learned anything by your post? Or do you think he just copied/pasted, without understand why what you did works?

  3. #3
    Registered User
    Join Date
    Dec 2009
    Posts
    9
    he only changed a couple of sections of the code and it's not like the program was completed because of it. I did understand the changes he made although there was no explanation. I just needed some help trying to figure out what was wrong.

  4. #4
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,650
    So, do you know why he did what he did? Or will you be back the next time you get similar errors?

    HINT: function prototyping
    Last edited by rags_to_riches; 12-10-2009 at 09:31 PM.

  5. #5
    Registered User
    Join Date
    Dec 2009
    Location
    /dev/pts/0
    Posts
    29
    May I point out, in sufoode's post, the full variable names are not in the function prototypes? While I realize they are not required, it is perhaps a good idea to put them in, to avoid some confusion, especially with editors that parse prototypes to enable auto-completion.

    Besides that, I concur with rags_to_riches. Simply posting a solution is not a good idea, as the OP does not necessarily learn as much that way.
    -- strange

    There is no Darkness in Eternity
    Only Light too dim for us to see

  6. #6
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    602
    It is interesting that you have declared your variables as global and yet you pass them as arguments to functions?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hi, Quiz C program Assignment updated
    By Eman in forum C Programming
    Replies: 19
    Last Post: 11-22-2009, 03:50 PM
  2. How to read a txt file into an array
    By Hitsugaya_KK in forum C Programming
    Replies: 49
    Last Post: 08-22-2009, 02:22 PM
  3. Suggestions for my Check Book program
    By Nor in forum C++ Programming
    Replies: 2
    Last Post: 11-17-2008, 05:44 PM
  4. program to check hard disk transfer rate
    By shadow99er in forum C Programming
    Replies: 3
    Last Post: 03-01-2002, 04:04 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

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