Help - Search - Members - Calendar
Full Version: C++ vs C
InsanelyMac Forum > Everything Else > Thunderdome (Random Stuff)
urlugal
I am for some reason having a bitch of a time with this and for some reason I can't figure it out. I want to create a formated list of output. I want to columns and a few rows. In ANSI C I can put a number in the statement like %3f, %4d it will do it but how do I do this in C++. I am using vi and g++ not XCode in case that makes a difference. I have tried looking online but I can't seem to find anything reasonable. Here is a chunk of the code, what I want to do it list the columns with a heading of length and a heading of time and then the respective units under them.

CODE
{
    // Variables

    char  start_input[8]; //this will either be planets, units, or start
    
    cout << "This will tell you the distance between two planets and how long it will take for you to get there.  You have your choice of units of measure.\n " << endl;

    cout << "1. For a list of supported locations type planets."  << endl;
    cout << "2. For a list of supported units type units." << endl;
    cout << "3. To start type start." << endl;

    cin >> start_input;
        if (strcmp ( start_input, "planets") ==0 )
            cout << endl << "Mercury Venus Earth Mars Jupiter Saturn Uranus Neptune Pluto \n" << endl;
        else if (strcmp ( start_input, "units") ==0 )
---->>        cout << "meters kilometers parsecs AU seconds days months years \n" << endl;
        else if (strcmp ( start_input, "start") ==0 )
            cout << "start \n" << endl;
        else cout << "learn to read English \n" << endl;
return 0;
}

It's a small scale program I am writing to teach myself C++, that gives the time and distance between any two planets and the user will be able to select the units.

Thanks,

Matty
Superhai
cout can use stream manipulators... look at http://www.cplusplus.com/reference/iostream/ostream/ should help you
urlugal
Thanks for the link.
NickF
'\t' won't do it?
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.