i have a question.
also, can someone tell me what have i done wrong on line 2???
@imqwerty
why's there an error on line number 9??
``` // // Conversion - Program to convert temperature from Celcius degrees into Fahrenheit: // Fahrenheit = Celsius * (212 - 32)/100 + 32) #include <cstdio> #include <cstdlib> #include <iostream> int main(int nNumberofArgs, chars * pszArgs[]) { //enter the temperature in Celsius int celsius; cout << "Enter the temperature in Celcius:"; cin >> celsius; //calculate conversion factor for Celsius //to Fahrenheit int factor; factor = 212 - 32; //use conversion factor to convert Celsius //into Fahrenheit values int fahrenheit; fahrenheit = factor * celsius/100 +32; //output the results (followed by a Newline) cout << "Fahrenheit value is:" ; cout << fahrenheit << endl; //wait until user is ready before terminating program //to allow the user to see the program results cout << "Press Enter to continue..." <<emdl; cin.ignore(10, '\n'); cin.get(); return 0; } ```
\(\color{#0cbb34}{\text{Originally Posted by}}\) @Ballery1 \(\color{#0cbb34}{\text{End of Quote}}\) you use \(\color{blue}{endl}\) whenever you want to start writing from a new line endl is similar to the new line character \(\color{green}{\backslash n}\) which can be used instead of endl to denote a new line it's not at all necessary to use endl, you just use it whenever you want to start from a new line.
i see. i have few more questions :)
\(\color{#0cbb34}{\text{Originally Posted by}}\) @Ballery1 also, can someone tell me what have i done wrong on line 2??? \(\color{#0cbb34}{\text{End of Quote}}\) i think stdafx.h is only limited to VS Code? you might have to copy the stdafx file into your project folder from VS Code to make it run just comment out the second line, you don't need it anyways bcz you're just using cout
instead of that *stdafx.h* i inserted stacked and the code worked. idk why ? lol
\(\color{#0cbb34}{\text{Originally Posted by}}\) @Ballery1 instead of that *stdafx.h* i inserted stacked and the code worked. idk why ? lol \(\color{#0cbb34}{\text{End of Quote}}\) what's stacked? lol
what does that mean? i'm scared *~* int ain (int nNumberofArgs, chars * pszArgs) what does the stuff in the brackets represents?
\(\color{#0cbb34}{\text{Originally Posted by}}\) @Ballery1 what does that mean? i'm scared *~* int ain (int nNumberofArgs, chars * pszArgs) what does the stuff in the brackets represents? \(\color{#0cbb34}{\text{End of Quote}}\) nvm, it's \(\large\color{green}{{char}}\) and not \(\large\color{red}{chars}\)
no but i need to know what's *nNumberofArgs* and *pszArgs* mean?
add this as well: using namespace std;
what's Args? and pszArgs?
the main function is the first function that executes so if you wanted to parse some arguments into the main function you'd do you right when you invoke your program from the command line int main(int nNumberofArgs, char * pszArgs[]) those arguments refer to the command line arguments, so if you do g++ fileName.cpp x y z a b c then the value of nNumberofArgs will be 6 and you pszArgs will be an array having elements as {'x', 'y', 'z', 'a', 'b', 'c'}
what do you mean by "Parse some arguments into the main function"? i'm sorry, idk these technical words.
Also ``` // This program calculates the user's pay. #include <iostream> using namespace std; int main() { double hours, rate, pay; // Get the number of hours worked. cout <<"How many hours did you work?" ; cin >> hours; // Get the hourly pay rate. cout <<"How much do yo uget paid per hour?" ; cin >> rate; // Calcualte the pay. pay = hours * rate; //Display the pay. cout << "You have earned $ " << pay << endl; return 0; } ``` on line 8, why's there a "double" beside hours, rate, pay?? what does it mean ?
\(\color{#0cbb34}{\text{Originally Posted by}}\) @imqwerty the main function is the first function that executes so if you wanted to parse some arguments into the main function you'd do you right when you invoke your program from the command line int main(int nNumberofArgs, char * pszArgs[]) those arguments refer to the command line arguments, so if you do g++ fileName.cpp x y z a b c then the value of nNumberofArgs will be 6 and you pszArgs will be an array having elements as {'x', 'y', 'z', 'a', 'b', 'c'} \(\color{#0cbb34}{\text{End of Quote}}\) correction- it should be- $ g++ filename.cpp -o main $ ./main x y z a b c instead of $ g++ filename.cpp x y z a b c
double is a datatype, just like int and char use it whenever you're dealing with decimal values
does it help calculate decimal values or what ?
yeah, you can't work with decimal values if your variables are int, you need to have a double or float
\(\color{#0cbb34}{\text{Originally Posted by}}\) @Ballery1 what do you mean by "Parse some arguments into the main function"? i'm sorry, idk these technical words. \(\color{#0cbb34}{\text{End of Quote}}\) are you familiar with functions?
i'm only familiar with like four functions and even they're sucking the soul out of my life rn. int, bool, void and char
those are not functions
oof RIP
are they called variables ?
int, bool and char are primitive data types and void is a return type
i was literally gonna ask you about this list of things i have saved as a picture. i was gonna ask you, do i need to remember all of them and their applications???
you don't have to memorize that
even for the exams and test ?
it's like how you meet people, you don't have to memorize their names, and faces you just get familiar with them over time? lol
i see... so what were you talking about functions??
doesn't the function starts from int main() ? so like everything inside the curly brackets is the function ???
main() is a function, but you can have more functions
before starting functions you should atleast know what a return type is and the concept of datatypes
listening* :) <3
``` #include<iostream> using namespace std; void function1(){ cout<<"I'm Speaking from function1"; } int function2(){ return 2; } int function3(int a, int b){ reuturn a+b; } int main(){ cout<<"Hello World"; function1(); int x = function2(); int z = function3(1,6); return 0; } ```
i've made 4 functions in this example
what if i run them??? what will i get?
i guess you didn't make every function a returning function correct?
yep function1 is void
void functions don't have to return anything
why does it look so intimidating ?
i'll explain it, it's rlly not that complicated
so there are four functions their names: main, function1, function2, function3
i'll start by explain what each function does and then we'll see how to program runs
listening* :)))))))))))))
function1 the return type of function1 is \(void\) so it doesn't have to return anything whenever the function1 is called it just does what it's supposed to do and ends without returning anything in this case, the function1 outputs this string: I'm Speaking from function1
how to know the reuturn type of a function? it's specified before the name of the function \(\color{green}{void~}{~function1(){ ... }}\)
i see, i have a quick question here master. :))))))))) so if you're running 4 different functions and 3 of them are return functions. how will it show on the cmd?? like do you have to draw long horizontal lines between each function to distinguish each one??? if not...can you still do it?
master, did you mean "return" or "reuturn"? please clarify that :)))))
nope you don't have to draw any lines lol, we'll come to that later and yes *return
icy now
for now, just know what each function is supposed to do, after that we'd see how all the functions get executed
okie dokie :))))))))
btw i can't run your code on my silly code block *~*
is it clear what function1 is supposed to do when it gets called?
because i have like 3 different projects opened already :/
i'm trying to absorb this. please give me few minutes to make sense of all this :)))))
you can run it on any online IDE i made some fixes in the code- https://ide.geeksforgeeks.org/zafi4XrTNt
oh yes i see now.... so what you want to do with a function is define by the name of the function in the very beginning... if you want to calculate integers... you put int, if you want no return.. you put void, if you are working with characters, you put chars etc
wdym by define the name of the function at the very beginning?
\(\color{#0cbb34}{\text{Originally Posted by}}\) @Ballery1 oh yes i see now.... so what you want to do with a function is define by the name of the function in the very beginning... if you want to calculate integers... you put int, if you want no return.. you put void, if you are working with characters, you put chars etc \(\color{#0cbb34}{\text{End of Quote}}\) you can stick to this definition for now, but it's not exactly perfect
one second plz. i'm trying to find an example...
aight
that's what i mean... like you wrote 4 different types of functions... each one has its own function and its own purpose.
o so i have a question... so know when you put cout and cin.....is it true that when you tpe cout the arrows are always pointing to the left like this << and when you type cin, the arrows are pointing to the right like this >>??please clarify that :))
yep, it has to be like cout << and cin >>
ok thanks ... i'm teaching myself how to print anything and i tried stuff in the list form and they're not showing up for some reason... one sec let me post.
``` #include <<iostream>> using namespace std; int main; { cout << "Need For Speed Carbon!" << endl; cout << "King of fighters" << endl; cout << "Density" << endl; return 0; } ```
what am i doing wrong here master? :)))))))
the first line, it should be #include<iostream>
do i not.....nvm o///o
``` #include <iostream> using namespace std; int main() { cout << "Need For Speed Carbon!" << endl; cout << "King of fighters" << endl; cout << "Density" << endl; return 0; } ```
why is this still not printing??? *~*
i've corrected everything :/
what error does it throw? did you save it / compiled before running?
it says return wasn't declared i nthe scope
this is what i'm getting
it could be because return 0; isn't aligned properly
\(\color{#0cbb34}{\text{Originally Posted by}}\) @Ballery1 this is what i'm getting \(\color{#0cbb34}{\text{End of Quote}}\) that should be *return
run this instead- i fixed some bugs ``` #include<iostream> using namespace std; void function1(){ cout<<"I'm Speaking from function1"<<endl; } int function2(){ return 2; } int function3(int a, int b){ return a+b; } int main(){ cout<<"Hello World, I'm speaking from the main function"<<endl; function1(); int x = function2(); int z = function3(1,6); cout << "x is: " << x << endl << "z is: " << z << endl; return 0; }
i think the reason it isn't working because i have multiple projects opened...
let me close them and run em one by one.
yup, your code worked just fine. let me test each of them one by one.
``` // // Conversion - Program to convert temperature from Celcius degrees into Fahrenheit: // Fahrenheit = Celsius * (212 - 32)/100 + 32) #include <cstdio> #include <cstdlib> #include <iostream> int main(int nNumberofArgs, char * pszArgs[]) { //enter the temperature in Celsius int celsius; cout << "Enter the temperature in Celcius:"; cin >> celsius; //calculate conversion factor for Celsius //to Fahrenheit int factor; factor = 212 - 32; //use conversion factor to convert Celsius //into Fahrenheit values int fahrenheit; fahrenheit = factor * celsius/100 +32; //output the results (followed by a Newline) cout << "Fahrenheit value is:" ; cout << fahrenheit << endl; //wait until user is ready before terminating program //to allow the user to see the program results cout << "Press Enter to continue..." <<emdl; cin.ignore(10, '\n'); cin.get(); return 0; } ``` i'm getting error on line 14, 28, and 32
i'm getting errors on line 14, 28, and 32. what am i doing wrong master? :))))))
you forgot using namespace std;
oof... can u tell which line???
#include <cstdio> #include <cstdlib> #include <iostream> \(\large\color{blue}{using~namespace~std}\)
yay!! it worked!! WOOOOOOOOOOOOOOW! XD
yeah XD
lmao you should be debugging it yourself
i literally just started programming like less than 2 days ago... XD gimme some time master
also, can you please tell me if i need to write all those three preprocessors at the top???
wouldn't just iostream do the trick ?
yep, you just need iostream
okie dokie :)))
btw what is the first two preprocessors are used for?
let's see if my code knows that at -45 F the celsius is also -45 khekhekhekhe
i don't exactly know but ig cstdlib have functions which can be used to allocate memory from the heap and cstdio probaby has some input output functions
ok thanks :))))))
np
Join our real-time social learning platform and learn together with your friends!