Jump to content

C++ vs C


4 posts in this topic

Recommended Posts

I am for some reason having a {censored} 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.


// 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.





Link to comment
Share on other sites


  • Create New...