I am totally new to programming, but i have a good understanding of the basics. My problem is I have trouble starting or understanding what is being asked of me with certain programs.
Ex. Exercise 1: Develop a design that leads to an algorithm and a program that will
read in a number that represents the number of kilometers traveled. The
output will convert this number to miles. 1 kilometer = 0.621 miles. Call
this program kilotomiles.cpp.
This is a lab assignment that im doing for practice. I know what to do at the same time i don't know what to do. I know that sounds wierd but thats my situation. Any helpful tips would be greatly appreciated.
Also is flowcharting better than pseudocode for planning or is it not a big deal which one you use?
This is what I came up w/ concerning the lab:
#include <iostream>
using namespace std;
int main()
{
double onekilo, miles = 0.621, total;
// Ask the user to enter in
// the number of kilos traveled.
cout << "How many kilos did you travel today?\n";
cin >> onekilo;
// Calculate total
total = onekilo * miles;
// Display the kilos in miles
cout << "So you traveled " << total << " miles today!\n";
return 0;
}
Any ideas on how this could have been executed better?
Well... you could declare miles to be const (constant) like this: constdouble miles = 0.621;. Also if you just want to print the number of miles, you don't need another variable, you can just do something like this: cout<<"So you traveled " <<onekilo * miles<<" miles today!\n"<<endl;.