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

I need someone who is familiar with C++ to help me with this program that I'm trying to create..

OpenStudy (bahrom7893):

I have two questions actually.. Well first one is probably simpler: So i'm making a basic program (I'm new to programming) that converts meters to kilometers..

OpenStudy (bahrom7893):

This is the code: #include <math.h> #include <conio.h> #include <iostream> #include "stdafx.h" using namespace std; int main() {float Meters, Kilometers; cout<<"Meters="; cin>>Meters; Kilometers=Meters/1000; cout<<Meters<<" Meters is "<<Kilometers<<" Kilometers""\n"; system ("pause"); return 0; }

OpenStudy (bahrom7893):

But I was wondering if I could like make a shell for it instead of doing it in that ugly looking command prompt like screen..

OpenStudy (bahrom7893):

you know right now it runs on that command prompt type black screen but I want it to be like an actual program, is there any way I can do that?

OpenStudy (bahrom7893):

there probably is so the right question would be, how would I do that?

OpenStudy (anonymous):

u want it to be an program that u open and u use some kind of GUI instead of using a terminal ?

OpenStudy (bahrom7893):

yes

OpenStudy (anonymous):

well am not am expert in this, if u are on linux u can use GTK or QT, but it will be a really boring thing to write an interface to make such a simple thing. On windows i have never done a program for it, so i dont know. Java have its on GUI its easy to use and works on windows, QT i think it works too, but i dont know.

OpenStudy (bahrom7893):

Ohh I'm just at 0 level in programming and i just started playing around with it today since my programming class starts in four days, i guess that will have to wait..

OpenStudy (anonymous):

Let me give you some advice. Forget about fancy UIs if you are actually trying to do some computations. A UI only matters if you are trying to release a product or tool for end users. You will just be wasting your time.

OpenStudy (bahrom7893):

oh okay and alchemista why is that that some #include commands have: <> and others have "": like: #include "stdafx.h" #include <Windows.h>

OpenStudy (anonymous):

the angle brackets signify that it should look for the include in the system/standard set of includes the quotes usually signify that the include is in the project itself.

OpenStudy (bahrom7893):

Okay now here's another thing, if I don't need a GUI, how can I do this? Right now I have a program that when u run it asks u for meters= then u put in a number it shows that in km and then it asks for km and if u put in a number it shows u meters. Now how can I make an option like even before it asks me for meters, i want it to have like 2 options: M -> Km Km -> M and depending on which option i pick to convert from there..

OpenStudy (anonymous):

You can setup a text based menu. It will first ask you for the menu item number, say 1 for M -> Km and 2 for Km to M.

OpenStudy (anonymous):

Then ask for the data and do the appropriate conversion.

OpenStudy (bahrom7893):

oh okay.. alchemista can u give me a code for like one option and i'll work from there for the 2nd option?

OpenStudy (anonymous):

if u are starting i recommend an easier lenguage. First start with the basics, assigment, conditionals, loops, procedures, functions. Pascal its a good one for that. Then u can go for and object oriented, go with Java. After that u can go for a more complex things like C where u need to do the memory managment, or C++. If u want to go further u can learn other types of lenguages like functionals or logicals, like haskell or Prolog. For ur question, ask how u want to convert and save it in a variable and then make and if statement one for Km->m and the other for the inverse.

OpenStudy (anonymous):

He's taking a C++ course. It would be pretty silly to learn another language right before you start.

OpenStudy (bahrom7893):

"For ur question, ask how u want to convert and save it in a variable and then make and if statement one for Km->m and the other for the inverse." I am at 0 right now, how would I do that? And I don't want to get into some other language because yea as alchemista said ima start a C++ in 4 days and i will get lost tryin to learn both..

OpenStudy (anonymous):

One second.

OpenStudy (bahrom7893):

okay actually alchemista this thread is getting really long and it's getting slow i'll just post a new question..

OpenStudy (anonymous):

ok

OpenStudy (anonymous):

o lol, didnt know that, well u do something like this int option; cout << "Enter ur option:\n1) Km->m\n2)m->Km" << endl; cin >> option; if(option ==1){ //code for Km->m } else if(option == 2){ //code for m->Km } else cout << "Wrong option" << endl;

OpenStudy (anonymous):

#include <iostream> using namespace std; int main () { char choice; float value; cout << "Select choice:" << endl << "1) Km -> M" << endl << "2) M -> Km" << endl; for ( ;; ) { cout << "Select: " << flush; cin >> choice; switch ( choice ) { case '1': break; case '2': cout << "Meters=" << flush; cin >> value; cout << value << " meters is " << value/1000.0 << " kilometers." << endl; break; default: cout << "Unknown choice!" << endl; } } return 0; }

OpenStudy (bahrom7893):

oh okay thanks a lot!

OpenStudy (anonymous):

Look at my version, its much cleaner =P

OpenStudy (bahrom7893):

yea i know now i have to study it..

OpenStudy (bahrom7893):

thanks! let me mess around with it a bit..

OpenStudy (bahrom7893):

hmm alchemista im getting an error..well not error something is wrong sort of..

OpenStudy (anonymous):

You need to fill in option 1

OpenStudy (anonymous):

only 2 works right now.

OpenStudy (bahrom7893):

ohh okay thanks! i see cuz when I picked 1 it just asked me to select again haha..

OpenStudy (anonymous):

I can finish it for you, but you asked me to only do one.

OpenStudy (bahrom7893):

no ill do it..

OpenStudy (anonymous):

well gl with it!

OpenStudy (bahrom7893):

thanks and now alchemista here's another thing..

OpenStudy (bahrom7893):

I did this: int main () { char choice; float value; cout << "Select choice:" << endl << "1) Km -> M" << endl << "2) M -> Km" << endl; for ( ;; ) { cout << "Select: " << flush; cin >> choice; switch ( choice ) { case '1': cout << "Kilometers=" << flush; cin >> value; cout << value << " kilometers is " << value*1000.0 << " meters." << endl; case '2': cout << "Meters=" << flush; cin >> value; cout << value << " meters is " << value/1000.0 << " kilometers." << endl; break; default: cout << "Unknown choice!" << endl; } } return 0; }

OpenStudy (anonymous):

you forgot to break

OpenStudy (anonymous):

add break; at the end

OpenStudy (bahrom7893):

and say I entered Select: 1 then it asked me for kilometers and converted that. After that it i asking me for Meters. how can i stop it from doing so? ohh that's the break i guess that's why..

OpenStudy (anonymous):

also lets work in a new thread.

OpenStudy (bahrom7893):

okay

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!