Alchemista and fedep3 let's continue here
i hate it when the thread gets too long
here we go Alchemista..
ok
okay now it works thanks ill work with more options. hopefully by the end of today ima add meters to feet and backwards and kilometers to miles and backwards and farenheit to celsius and backwards..
Oh also alchemista can I add Choice 3 - Exit then would I sort of set return 0; for choice 3?
yes that would work.
case '3': return 0;
do I need a break at the end too?
Also I think I should let you know why we are using single quotes around the numbers. What we are actually comparing with is the ASCII value of the numbers not the number itself.
no because you are already returning from the function.
oh okay and what is the ASCII value of numbers oh i have this weird table in my book so if I were to pick the option not 1 2 and 3 but a b and c instead of putting '1' i would put 'ASCII for a' ?
well 1 won't be ascii for a, but it certainly wont be ascii for '1'
daang.. am i going to have to memorize all that?
no
nop
thats the point of the single quotes.
thats what I was trying to tell you, the reason we are using single quotes around the numbers.
It tells the C++ compiler we want the ascii value of '1' not 1 itself.
ohhh i see if we did not have them we'd have to put the actual ascii right?
* i mean if we didnt have quotes..
yes thats right!
okay good.. now i want to know what these stand for: for ( ;; )
its an infinite loop.
ohh so until i select 3 (exit choice) i will keep getting that select option?
the for loop has three parts the first is for declaring variables, the second is a condition, the third is a statement
but since we have no conditions it will just loop forever.
in the for u have first the initialitation, then the condition and at last what u gonna do after u do the stament of the cicle
okay so it's like: for (initiation;condition;what i will do) ?
for ( int i = 0; i < 10; i++ ) cout << i << endl;
thats an example
that will print the numbers from 0-9
okay.. i see
ill put in a more simple way the for its a while so if u have for(a;b;c) { d;} its a: a; while(b){ d; c; }
yes pretty much although there is a small difference in these two examples.
a is only in the scope of the for loop
in the while loop example a does not go out of scope after the while loop
yea thats true
okay guys i will be back in like 10 minutes let me add a couple of more converters to that..
thanks for the help ! =)
i g2g, sry! but if u want to practice more, there are some good problems here http://www.spoj.pl/problems/classical/sort=-6, the first ones are the ones that have been solved by more users, and are the easiest ones, gl!
u can google too more about c++
also most of the things we talked about were valid in C
except the stream operations
alchemista what is wrong here?
#include <iostream> using namespace std; int main () { char choice; float value; cout << "Select choice:" << endl << "1) Kilometers -> Meters" << endl << "2) Meters -> Kilometers" << endl << "3) Feet -> Meters " << endl << "4) Exit" << end1; for ( ;; ) { cout << "Select: " << flush; cin >> choice; switch ( choice ) { case '1': cout << "Kilometers=" << flush; cin >> value; cout << value << " kilometers is " << value*1000.0 << " meters." << endl; break; case '2': cout << "Meters=" << flush; cin >> value; cout << value << " meters is " << value/1000.0 << " kilometers." << endl; break; case '3': cout<< "Feet=" << flush; cin >> value; cout << value << " feet is " << value*0.3048 << " meters." << end1; case '4': return 0; default: cout << "Unknown choice!" << endl; } } }
it is underlining that end1; at the 4)Exit part..
you forgot the break again.
ohhh okay thanks
it still failed..
is it not compiling?
<< "4) Exit" << end1; This end1; is being underlined as a mistake
one second
its endl the letter l as in leo the lion not 1
ohh wow haha! I see thanks! never noticed that..
does that mean endline?
yes of course
oh okay thanks if i have another question i will post it as a new thread.. Man you save me all over the place... with lin algebra and this too now i really appreciate ur help..
Join our real-time social learning platform and learn together with your friends!