Ask your own question, for FREE!
Mathematics 11 Online
OpenStudy (bahrom7893):

Imran here's the .txt file

OpenStudy (bahrom7893):

there amistre helped me a lot with this..

OpenStudy (anonymous):

oh using switch statement already, nice

OpenStudy (bahrom7893):

sorry i meant alchemista..!

OpenStudy (bahrom7893):

Alchemista was helpin me a lot! I mean all i could do is just add more options and write those little converters..

OpenStudy (bahrom7893):

and that problem solver with the train..

OpenStudy (anonymous):

yep you are using function(or method) already

OpenStudy (anonymous):

You will learn object soon, those are pain

OpenStudy (bahrom7893):

right now im doing the max of two, three, etc.. numbers..

OpenStudy (bahrom7893):

using if else etc..

OpenStudy (anonymous):

here

OpenStudy (anonymous):

ill show you a nicer way of doing this.

OpenStudy (bahrom7893):

okay! that'd be great!

OpenStudy (anonymous):

using loop you can do it much smoother

OpenStudy (anonymous):

make a max variable, go through the loop if value at the loop is bigger than max value, change max value

OpenStudy (bahrom7893):

no im doing like easy stuff for now..

OpenStudy (bahrom7893):

#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; }

OpenStudy (anonymous):

// 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; } } }

OpenStudy (bahrom7893):

okay this was for that solvers and converters right.. okay let me see.. this

OpenStudy (anonymous):

just for converters. its a better way of organizing the code.

OpenStudy (bahrom7893):

okay i will take a look at this once i finish the max min of two or more numbers stuff..

OpenStudy (anonymous):

float max ( a, b ) { return a > b ? a : b; } float min ( a, b ) { return a < b ? a : b; }

OpenStudy (anonymous):

Thats the "ternary" operator: ( condition ) ? evaluate_if_true : evaluate_if_false;

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!