Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1069761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:28:08+00:00 2026-05-16T20:28:08+00:00

Okay, for a homework assignment my professor wants us to write a program in

  • 0

Okay, for a homework assignment my professor wants us to write a program in C++ that converts from miles to km. I did all that, the program runs. However, he has this special way of calling the program:

The program’s usage options are based
on the NAME of the BINARY FILE. If
the program name is ‘km2miles’, the
program interprets the command line
argument as a kilometer value to
convert to miles. If the name is
‘miles2km’, then it interprets as
miles being converted to km. Since the
first command line argument, argv[0]
is always the program’s name, you can
use its value to decide which function
to call.

I only have 3 files in this project (he tells us to ONLY have these 3):
convert.cpp
distance.cpp
distance.h

Distance .h and .cpp have the different functions to convert Mi to Km and Vice Versa, the convert.cpp has the main function. However, the only way I know how to call this program (after compiling it) is to say:

./convert 10

Where 10 is the number to convert. He says it should be called like this:

$ km2miles 100

and

$ miles2km 60

I have no idea how to get the program to act differently by having a different name… especially when that name doesn’t even run the program! Help would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T20:28:08+00:00Added an answer on May 16, 2026 at 8:28 pm

    You can:

    • specify a name when you build it, and build it twice
    • on Windows: copy convert miles2kms; copy convert kms2miles
    • on UNIX/Linux: cp convert miles2kms; cp convert kms2miles
    • on UNIX/Linx (better): make a link or symbolic link: ln -s convert miles2kms; ln -s convert kms2miles.

    Inside your program, you should be doing something like:

    #include <string>
    #include <iostream>
    
    int main(int argc, const char* argv[])
    {
        std::string program_name = argv[0];
    
        if (argc != 2) {
            std::cerr << "usage: " << program_name << " <value>\n";
            return 0;
        }
        if (/* TODO: what would go here? */)
            ...
        else
            ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay so I made this program to help me out with my homework and
Okay! I really need your help or some tips I need a program that
Okay, I did my homework and search SO, and indeed I found similar questions
Okay one of my homework problems is to take a list of lists and
Okay, so I have another question on a prolog homework problem I am struggling
Okay, next PHPExcel question. I have an HTML form that users fill out and
Okay - I have a dilemma. So far my script converts page titles into
okay, i'm setting up a multi-user chat system. i have a messages table, that
Okay - yes, this is homework, but it isn't mine. I have a friend
I am creating a linked list function for homework that adds at any index

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.