New to C++ and don't know how to do stuff on windows

I started a C++ class about 2 weeks ago. In the class I use Linux and I can get stuff to work, but at home I have WindowsXP pro and I don't know how to make anything work. I wrote this simple code that tells you your travel efficiency:

#include

using std::cin;
using std::cout;

int main()

{
float milestraveled;
float gallonsused;
float pricepergallon;
float pricepermile;
float milespergallon;

cout << "How many miles did you travel? ";
cin >> milestraveled;
cout << "How many gallons of gas did you use? ";
cin >> gallonsused;
cout >> "How much gas does one gallon of gas cost? $";
cin >> pricepergallon;

milespergallon = milestraveled / gallonsused;
pricepermile = pricepergallon / milespergallon;

cout << "You got " << milespergallon << " miles per gallon,
";
cout << "and each mile cost $" << pricepermile << '
';
return 0;
}

I can't get it to compile. It works just fine when I use this in Linux. What do I have to do differently with windows to make it work? After I get it to work how can I run it to see if it works. In linux I just type ./travel to make it work. I'm guessing that I have to use command prompt, but I don't know the commands. Is there somewhere I can go to find a tutorial to make my code a clickable executable file like a batch or something? I have been using devc++ for compiling.

Comments

  • : I started a C++ class about 2 weeks ago. In the class I use Linux and I can get stuff to work, but at home I have WindowsXP pro and I don't know how to make anything work. I wrote this simple code that tells you your travel efficiency:
    :
    : #include
    :
    : using std::cin;
    : using std::cout;
    :
    : int main()
    :
    : {
    : float milestraveled;
    : float gallonsused;
    : float pricepergallon;
    : float pricepermile;
    : float milespergallon;
    :
    : cout << "How many miles did you travel? ";
    : cin >> milestraveled;
    : cout << "How many gallons of gas did you use? ";
    : cin >> gallonsused;
    : cout >> "How much gas does one gallon of gas cost? $";
    : cin >> pricepergallon;
    :
    : milespergallon = milestraveled / gallonsused;
    : pricepermile = pricepergallon / milespergallon;
    :
    : cout << "You got " << milespergallon << " miles per gallon,
    ";
    : cout << "and each mile cost $" << pricepermile << '
    ';
    : return 0;
    : }
    :
    : I can't get it to compile. It works just fine when I use this in Linux. What do I have to do differently with windows to make it work? After I get it to work how can I run it to see if it works. In linux I just type ./travel to make it work. I'm guessing that I have to use command prompt, but I don't know the commands. Is there somewhere I can go to find a tutorial to make my code a clickable executable file like a batch or something? I have been using devc++ for compiling.
    :
    [BLUE]
    I didn't look through your code throughley,
    but I did notice one thing:[/BLUE][CODE]
    [RED]cout >> "How much gas does one gallon of gas cost? $";[/RED]
    cin >> pricepergallon;[/CODE][BLUE]
    std::cout uses the overloaded '<<' operator,
    not the '>>' operator..

    Nontheless, it should work ok with Windows.

    As for the command prompt, after bringing it up,
    use the 'cd' (change directory) command
    to go to the directory of the program:[/BLUE][CODE]
    [BLUE]C:[/BLUE]cd c:myDirectorymyProg[/CODE][BLUE]
    Then just type in the name of the program.

    There are plenty of resources on the internet for
    the counsol commands--google is your friend.

    Good Luck,

    ~MT2002[/BLUE]
  • [b][red]This message was edited by Maggot(8) at 2004-9-6 20:2:43[/red][/b][hr]
    : :
    : [BLUE]
    : I didn't look through your code throughley,
    : but I did notice one thing:[/BLUE][CODE]
    : [RED]cout >> "How much gas does one gallon of gas cost? $";[/RED]
    : cin >> pricepergallon;[/CODE][BLUE]
    : std::cout uses the overloaded '<<' operator,
    : not the '>>' operator..
    :
    : Nontheless, it should work ok with Windows.
    :
    : As for the command prompt, after bringing it up,
    : use the 'cd' (change directory) command
    : to go to the directory of the program:[/BLUE][CODE]
    : [BLUE]C:[/BLUE]cd c:myDirectorymyProg[/CODE][BLUE]
    : Then just type in the name of the program.
    :
    : There are plenty of resources on the internet for
    : the counsol commands--google is your friend.
    :
    : Good Luck,
    :
    : ~MT2002[/BLUE]
    :


    I fixed the '>>' problem but I still can't get it to compile. you can see the error message here [url]http://img.photobucket.com/albums/v238/Maggot8/Other Stuff/devc.jpg[/url]
    Any help would be appreciated.


  • : [b][red]This message was edited by Maggot(8) at 2004-9-6 20:2:43[/red][/b][hr]
    : : :
    : : [BLUE]
    : : I didn't look through your code throughley,
    : : but I did notice one thing:[/BLUE][CODE]
    : : [RED]cout >> "How much gas does one gallon of gas cost? $";[/RED]
    : : cin >> pricepergallon;[/CODE][BLUE]
    : : std::cout uses the overloaded '<<' operator,
    : : not the '>>' operator..
    : :
    : : Nontheless, it should work ok with Windows.
    : :
    : : As for the command prompt, after bringing it up,
    : : use the 'cd' (change directory) command
    : : to go to the directory of the program:[/BLUE][CODE]
    : : [BLUE]C:[/BLUE]cd c:myDirectorymyProg[/CODE][BLUE]
    : : Then just type in the name of the program.
    : :
    : : There are plenty of resources on the internet for
    : : the counsol commands--google is your friend.
    : :
    : : Good Luck,
    : :
    : : ~MT2002[/BLUE]
    : :
    :
    :
    : I fixed the '>>' problem but I still can't get it to compile. you can see the error message here [url]http://img.photobucket.com/albums/v238/Maggot8/Other Stuff/devc.jpg[/url]
    : Any help would be appreciated.
    :
    :
    :
    [BLUE]
    I believe you are mixing C++ (iostream) with C,
    which is causing the errors. I dont think its
    possible to use iostream in a C program. I
    could be incorrect though. (iostream uses
    some constructs specifiac to C++, ie;
    operator overloading).

    Compile your source as a C++ program, and it
    should work.

    If it must be C, why not try stdio.h?

    Also, for reference:[/BLUE][CODE]
    #include [GREEN] //C++[/GREEN]
    #include [GREEN] //C[/GREEN]
    [/CODE][BLUE]
    Only certian C++ standard heades omit the *.h.

    Good Luck;

    ~MT2002[/BLUE]
  • your program compiled without any errors or warnings with my compiler (vc++ 6.0) after changing >> to << as previously mentioned. The program must be in a *.cpp file, not *.c so that it will be compiled as a c++ program. I [b]think[/b] the standard naming convention for c++ programs on *nix is *.cc, so you will want to change the file name to *.cpp for Windows.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories