Like Tree1Likes
  • 1 Post By Salem

I'm missing something, apparenlty...

This is a discussion on I'm missing something, apparenlty... within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream> #include <string> using namespace std; string getInput(string); void start(string); void getName(string); void getAge(int); void getMileage(double); //declare variables ...

  1. #1
    Registered User
    Join Date
    Jan 2012
    Posts
    5

    I'm missing something, apparenlty...

    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    string getInput(string);
    void start(string);
    void getName(string);
    void getAge(int);
    void getMileage(double);
    //declare variables
    //input as string
    string userInput = "";
    //name as string
    string name = "";
    //age as integer
    int age = 0;
    //mileage as double
    double mileage = 0.0;
    int main ()
    {
    //call DisplayApplicationInformation
    cout << "This program accepts user input as a string, then makes the appropriate data conversion." << endl;
    start(startProgram);
    getName(name);
    getAge(age);
    getMileage(mileage);
    
    
    return 0;
    }//call DisplayDivider(“Start Program”)
    void start(string startProgram)
    {
    cout << "*********Start Program*********" << endl;
    }//call DisplayDivider(“Get Name”)
    void getName(string name)
    {
    //set name = GetInput(“Your Name”)
    userInput = getInput("Your Name: ");
    //display “Your name is: “ + name
    getline(cin, userInput);
    cout << "Your name is: " << name << endl;
    
    }
    //call DisplayDivider(“Get Age”)
    void getAge(int age)
    {
    //set input = GetInput(“Your Age”)
    userInput = getInput("Your Age: ");
    //set age = convert input to integer
    age = atoi(userInput.c_str());
    //display “Your age is: “ + age
    cout << "Your Age is: " << age << endl;
    }
    //call DisplayDivider(“Get Mileage”)
    void getMileage(double mileage)
    {
    //set input = GetInput(“Gas Mileage”)
    userInput = getInput("Gas Mileage: ");
    //set mileage = convert input to double
    mileage = atof(userInput.c_str());
    //display “Your car MPG is: “ + mileage
    cout << "Your car MPG is: " << mileage << endl;
    }
    error LNK2019: unresolved external symbol "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl getInput(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?getInput@@YA?AV?$basic_string@DU?$char_traits@D@ std@@V?$allocator@D@2@@std@@V12@@Z) referenced in function "void __cdecl getName(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?getName@@YAXV?$basic_string@DU?$char_traits@D@st d@@V?$allocator@D@2@@std@@@Z)

    I take out the void start(string) altogether or change it to
    void start() and I still get errors.
    Not sure what I'm missing.
    Last edited by cantcoderight; 01-07-2012 at 12:51 PM.

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,438
    You are defo missing indentation mate, thats a start, But its a bit of a mess beyond that too im afraid.
    global string objects ?? Thats just sick and wrong methinks,
    And you start the program, call start() which is supposed to take a string , (you should really use string& by the way) But you don't pass anything in, other than a word 'startProgram' from the code you have posted this is not declared as a variable of any kind anywhere, it is simply free text as far as the compiler is concerned, and makes no sense at all, you have written it as if it is a variable name, perhaps you meant to enclose it in quotes and then assign it in the function? to an actual string object?
    Its a mess man, sorry., apologies if i missed something obvious that would make sense of it but I really can't be bothered to properly read code that looks like that.

    And it is *much* better to give your function parameters names in the prototype declaration:
    Code:
     void GetFoo(int bar);
    Last edited by rogster001; 01-07-2012 at 01:18 PM.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    start with something simple

    Code:
    #include <string>
    int main()
    {
       std::string test ="Hello";
       return 0;
    }
    compile it and go from there - adding sever lines at time and compiling... In this manner you'll know which line gives you problems


    also atoi and atof - I would not use at all - read about stringstream class instead
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  4. #4
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,651
    You seem to want to call a function getInput() which does not exist.

  5. #5
    Registered User
    Join Date
    Jan 2012
    Posts
    5
    I kinda figured it was all over the place. The first class I took for this was so basic and elemtary that it ended barely covering a quarter of what I'm expected to here. I'm obviously lost in this portion of it. I copy and pasted into notepad then to here, and it didn't keep the indentation. It's kind of frustrating knowing that in order to get a degree in this field you have to actually have a moderate to advanced knowledge ahead of time to keep up. I could write this really simple program just for the ouput and what is needed to get the correct screenshot of the program, but these extra steps are required in this exercise. Thanks for the input though.
    Last edited by cantcoderight; 01-07-2012 at 02:34 PM.

  6. #6
    Registered User
    Join Date
    Jan 2012
    Posts
    5
    They would seem out of place converting strings to integers and doubles, especially in this, but it is what is required for this particular exercise.

    This is just the psuedocode for what is expected of this exercise.

    Start main
    Start main
    //declare variables
    input as string
    name as string
    age as integer
    mileage as double

    call DisplayApplicationInformation
    call DisplayDivider(“Start Program”)

    call DisplayDivider(“Get Name”)
    set name = GetInput(“Your Name”)
    display “Your name is: “ + name

    call DisplayDivider(“Get Age”)
    set input = GetInput(“Your Age”)
    set age = convert input to integer
    display “Your age is: “ + age

    call DisplayDivider(“Get Mileage”)
    set input = GetInput(“Gas Mileage”)
    set mileage = convert input to double
    //display mileage to 2 decimal places
    display “Your car MPG is: “ + mileage
    call TerminateApplication
    end main program

    procedure DisplayApplicationInformation
    display “Welcome the Basic User Interface Program”
    display “Name: YOUR NAME”
    display “This program accepts user input as a string, then makes the appropriate data conversion”
    end procedure

    DisplayDivider(string outputTitle)
    display “**************** “ + outputTitle + “****************”
    end procedure

    function GetInput(string inputType) as string
    strInput as string
    display “Enter the “ + inputType
    get strInput
    return strInput
    end function

    procedure TerminateApplication

    display “Thank you for using the Basic User Interface program”
    exit application
    end procedure
    I don't expect anyone to actually fix this, I was just hoping for some pointers. I understand how bad this looks, and I will listen to any advice offered.
    Last edited by cantcoderight; 01-07-2012 at 02:45 PM.

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,671
    One thing you DON'T do is look at someone else's hack at converting it to C#, then attempt to take that and convert it into C++.
    Please Help [Archive] - CodeGuru Forums

    Then you do some rather literal translations, say

    > Start main
    int main ( )

    > input as string
    Remove "as" and swap them over, and add a ;
    string input;

    > call DisplayApplicationInformation
    Remove "call" and append some (), and add a ;
    DisplayApplicationInformation();

    > set name = GetInput(“Your Name”)
    Remove "set" and add a ;
    name = GetInput(“Your Name”);

    For each new function name you come across, create a function prototype above main.

    That, and a few pairs of braces should get you somewhere close.

    >
    rogster001 likes this.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what am i missing now...
    By MK27 in forum C Programming
    Replies: 8
    Last Post: 09-15-2008, 03:13 AM
  2. Something I'm Missing...
    By Dukefrukem in forum C Programming
    Replies: 2
    Last Post: 07-09-2008, 01:47 PM
  3. I am missing something in regards to min?
    By BSmith4740 in forum C Programming
    Replies: 5
    Last Post: 06-14-2008, 11:26 AM
  4. Am i missing something?
    By Chaplin27 in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 03-08-2005, 02:27 AM
  5. Someone tell me what I'm missing here?
    By Furious_George in forum C++ Programming
    Replies: 7
    Last Post: 10-06-2003, 12:27 AM

Tags for this Thread


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