Imran here's the .txt file
there amistre helped me a lot with this..
oh using switch statement already, nice
sorry i meant alchemista..!
Alchemista was helpin me a lot! I mean all i could do is just add more options and write those little converters..
and that problem solver with the train..
yep you are using function(or method) already
You will learn object soon, those are pain
right now im doing the max of two, three, etc.. numbers..
using if else etc..
here
ill show you a nicer way of doing this.
okay! that'd be great!
using loop you can do it much smoother
make a max variable, go through the loop if value at the loop is bigger than max value, change max value
no im doing like easy stuff for now..
#include <math.h> #include <conio.h> #include <iostream> #include "stdafx.h" using namespace std; int main() {float First_number, Second_number, Minimum_value; cout<<"First number="; cin>>First_number; cout<<"Second number="; cin>>Second_number; if (First_number<Second_number) Minimum_value=First_number; else Minimum_value=Second_number; cout<<"Minimum value="<< Minimum_value; system ("pause"); return 0; }
// SolverandConverter.cpp : Defines the entry point for the console application. // #include <iostream> using namespace std; // Converter desc typedef float CONVERTER_T ( float input ); typedef struct _CONVERTER_DESC { const char* description; const char* unitsFrom; const char* unitsTo; CONVERTER_T* function; } CONVERTER_DESC, *PCONVERTER_DESC; // Converters float conv_kilometers_meters ( float input ) { return input * 1000.0; } float conv_meters_kilometers ( float input ) { return input / 1000.0; } float conv_feet_meters ( float input ) { return input * 0.3048; } float conv_meters_feet ( float input ) { return input / 0.3048; } float conv_farenheit_celcius ( float input ) { return (input-32.0)*(5.0/9.0); } // Converter list static CONVERTER_DESC g_converters [] = { { "Kilometers -> Meters", "kilometers", "meters", conv_kilometers_meters }, { "Meters -> Kilometers", "meters", "kilometers", conv_meters_kilometers }, { "Feet -> Meters", "feet", "meters", conv_feet_meters }, { "Meters -> Feet", "meters", "feet", conv_meters_feet }, { "Farenheit -> Celsius", "farenheit", "celcius", conv_farenheit_celcius }, { NULL, NULL } /* Setinel */ }; int converters () { int i; // List the available converters cout << "Available converters:" << endl; for ( i = 0; g_converters[i].description != NULL; i++ ) cout << i + 1 << ") " << g_converters[i].description << endl; cout << ++i << ") Leave menu" << endl; for ( ;; ) { // Fetch the choice int choice; cout << "Select: " << flush; cin >> choice; if ( choice < 1 || choice >= i ) { if ( choice == i ) return 0; cout << "Unknown choice!" << endl; continue; } choice -= 1; // Do the conversion float value; PCONVERTER_DESC converter = &g_converters[choice]; cout << (char) toupper ( converter->unitsFrom[0] ) << converter->unitsFrom + 1 << "=" << flush; cin >> value; cout << value << " " << converter->unitsFrom << " is " << converter->function ( value ) << " " << converter->unitsTo << "." << endl; } } int solvers () { // add your stuff here return 0; } int main () { char choice; float value; for ( ;; ) { cout << "1) Available converters" << endl << "2) Problem solvers" << endl << "3) Exit" << endl << "Select: " << flush; cin >> choice; switch ( choice ) { case '1': converters (); break; case '2': solvers (); break; case '3': return 0; default: cout << "Unknown choice!" << endl; } } }
okay this was for that solvers and converters right.. okay let me see.. this
just for converters. its a better way of organizing the code.
okay i will take a look at this once i finish the max min of two or more numbers stuff..
float max ( a, b ) { return a > b ? a : b; } float min ( a, b ) { return a < b ? a : b; }
Thats the "ternary" operator: ( condition ) ? evaluate_if_true : evaluate_if_false;
Join our real-time social learning platform and learn together with your friends!