Hello! I am currently a student pursuing a degree in computer engineering.
I want to eventually get into writing code and programming professionally.
I will be posting code that I write (Maybe a program a week) And asking for improvement in anyway possible.
The code will start out semi simple, and as I grow, it will grow with me.
If you suggest changes, please explain why you suggest the change and what effect it would have on the code, may it be speed wise or flow wise or what have you.
I want everyone to be able to learn from the improvements that are given to the code.
Here we go, this is a fairly simple program that converts celcius values to farenheit values by increments set by the user.
/* This progarm converts Celcius to farenheit. It does so by taking a user input
of a celcius temperature they would like to start at. It then asks for an end celcius
number. Finally, the program asks the user what imcriment they would like the program
to calculate farenheit differences in. */
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#include <iostream>
#define MAX_TEMP 50000
#define MIN_TEMP 0
using namespace std;
int main()
{
int start, end, step, stepDif, count; // Start is the temperature to start at. end is the temp to end at. step is the step size between calucations.
//stepDifference is the difference between end and start.
double cel, far, rep;
cout << "Welcome to the Temperature converter!" << endl;
cout << "Please enter in a minimum temperature above 0 in Celcius. " << endl;
cin >> start;
while(start < MIN_TEMP)
{
cout << "Please enter in a value above 0 in Celcius. " << endl;
cin >> start;
}
cout << "Please enter in a maxiumum temperature to end at below 50000 and above " << start << " in celcius."<< endl;
cin >> end;
while (end > MAX_TEMP || end < start)
{
cout << "Please enter a value below 50000, and above " << start << " in celcius." << endl;
cin >> end;
}
stepDif = end - start;
cout << "Next, enter a step value that is less than: " << stepDif << " celcius. "<< endl;
cin >> step;
while (step > stepDif)
{
cout << "Please enter a step value that is les than: " << stepDif << " celcius." << endl;
cin >> step;
}
cout << "Celcius " << " Farenheight" << endl;
cout << "_______ " << " ___________"<< endl;
rep = start;
for(count=0; rep<end; count++) // This loop is to add the step number to the celcius temp, and translate celcius into farenheit for every temp.
{
cel = rep;
far = rep*1.8-32;
cout << endl;
cout << rep << " " << far << " " << endl;
rep=rep+step;
}
cin >> count;
return 0;
}
|