### Need help first time

First time in C++ need some help on an assignment NOT LOOKING FOR ANYONE TO DO MY WORK FOR ME just need help or examples on what to do thank you the assignmen is below

Observe the formula: degrees C =  5(F - 32)/9Next  we can convert this formula so that it can be written in a formthat it can becomputed by a C++ program which we can develop. For example,/The followoing program computes  degrees centigrade# include <iostream>        //Directives for cin, cout, etc,    using  namespace std; // uses cin and cout in a standard way     int main() {                        double F, C;      //Here, I am delaring thevariables, F and C                                                 //before they used bythe program and I am                                                  //telling thecompiler that they will contain decimal                                                  // type data by usng'double before I declare the                                                  // variables           cout<<"Please enter a  degree Fahrenheit /n";                 cin>> F;                  C = (5*(F - 32))/9                     cout<<"degrees C=";C //centigrades                        return 0;}
Given: Interest =
PrincipalxRate x Time
Write a C++ program  to compute the Interest
Principal= 16,000
Rate=0.08
Time = 12 months
Enter the values via the keyboard
What exactly do you need help on?

At least make an attempt to make the program, and we can help you with your errors.
Last edited on
Well i dont have access to a computer to make the program im using my android to use the net but I wanted to write the program thats what I need help with.. im not sure how its just my first week and im still waiting for the books in the mail
 Well i dont have access to a computer to make the program

lol thats kinda a prerequisite.
Yea I understand its a prerequisite im working on it but for the moment I cant I would like to start out by being able to understand and write some c++ starting with the assignment I have above.. can anyone please help?

Thanks
Well what do you know so far? Is there a particular part your stuck on in your program? For example maybe your stuck on the math, or you're just forgetting a semicolon. What exactly don't you get?

Oh BTW you can write the program on a phone as long as there is a text editor on it (ie. notepad), although using a compiler on a computer is way better because it catches most of your mistakes.
Oo..ok I didnt know there was a way to do it on Your android thanks for the link..for your qustion I really dont know much im a newbie all the way what I know is maybe how to set something up with the cin, cout just I guess like 5 percent of basic c++

How do I write a c++ program to compute the interest
There's a tutorial on this website..
To write those programs you only need to understand how to declare and assign variables, use mathematical operators, and cin and cout.

#include <iostream>
using namespace std;

int main() {
float deg_f, deg_c;

cout << "Enter temp in F: ";
cin >> deg_f;
deg_c = // YOU DO THE MATH HERE ;

cout << "\nTemp in C = " << deg_c << "\n";
return 0;
}

That could be the structure of the program, a kind of basic way to make it.
Read about variable assignment and mathematical operators. The interest program would be similar.
Last edited on

Ok... ill look for the tutorial I understand part of what your saying where I get stuck at is the math part it confuses me...in the book I have it explains sort of what you just said but what im looking for is a more detailed example and what about the bottom part (p×r×t) am I looking for the I terest or am I doing the example C = (5*(F - 32))/9  im going to download the android app for the compiler so how would I write this out is it how it is above ^

And this part here contains what

#include <iostream>
using namespace std;
int main()
{float deg_f, deg_c;
So just bought the compiler for android from the link above... a little help on how to use it also and answer to my question above thank you

Sorry just a real noob but learning
lets go line by line

#include <iostream> // this includes the header file or whatever for iostream and allows you to use the cin and cout functions and other stuff

using namespace std; // this is optional, is the namespace for c++ std library.. I have seen lots of people instead of using this you can prefix your commands with std:: (e.g. "std::cout << string;") but that looks messy and I'm still not sure why they do it so just use "using namespace std;" then you won't have to worry about it

int main() // this is the entry point for a regular c++ program.. no matter what functions come before or after in the source, the main() func will be the first function called when program is executed.. as with any declaration of a function you must specify a return var type (int in this case, void may work too) the name of the function (main in this case, but for other functions any valid identifier can be used) then declare any other variables passed to the function in the parentheses. We're not using that in the main function so we just say "int main()". Once the function is declared, you use the squiggly brackets {} to list statements to be executed in order within the function. All statements must be separated by a semicolon ";". The program should terminate at the end of the main function. (thats what return does)

now for the stuff within the {}:

float deg_f, deg_c;
// this statement declares two floating point (allows any number of decimal places) variables (after re-reading your problem, you may wish to use "double" instead of "float", the difference is size) deg_f and deg_c which are the same as your F and C you could name them that if you wanted to. The important thing is: variable type then identifier, identifier.. semicolon";"
Any valid identifier will suffice I just like the format I used.. your professor might find it a lil strange so either of these lines can be used equivalently: (as long as you call the vars with the same name you give them in the declaration)

float deg_f, deg_c;
double F,C; //either one works.

now since you say you are familiar with c in and out, lets skip to the math bit.. to assign a value to a variable, start a statement like this:

deg_c =

anything after the "=" sign and before a ";" semicolon will be evaluated and assigned to the variable. (numbers are literal constants and get handled just like numbers should)
e.g: "deg_c = (5*(deg_f - 32)/9);"

This statement will, in compliance with order of operations, subtract 32 from deg_f, multiply by 5/9, and assign the value to deg_c, which can then be streamed to cout to display in the window like so:

cout << "Temp in C: " << deg_c << "\n";

Finally once we are all done with the important stuff, its time to close the program.

return 0;

So, this statement will end the main function. It actually does all kinds of cool stuff with error codes with a nonzero argument and shit but that's not important right now. Depending on software stuff I don't understand, your console should but MAY not pause and wait for a key to be pressed to close the window. Some folks may find that they run a program like this and the window immediately closes after execution (not letting them read the results of the program execution) if thats the case for you, we'll need to add a little function to pause, but that really shouldn't be necessary.

So that's pretty much it. Make sure your {} brackets are placed properly, and all statements end with a ";" (the #include statement doesn't need a semicolon, it is a preprocessor directive and is read as the entire line). Remember, with the exception of // comments and "#" preprocessor commands, the compiler ignores things like spaces, new lines, tabs.. Those formatting things are just to make the code aesthetically pleasing and easy to work with. The things that really determine the structure of a program are the control structure brackets {} and semicolons ";" between statements. These will probably be your most common errors at first so look out for lines with no ";"!

As far as how to use your compiler.. I can tell you how to write the code but you're going to have to figure out your software I dunno anything about it. Use your help files. Btw, everything I covered here can also be found in these tutorials:

http://www.cplusplus.com/doc/tutorial/program_structure/
http://www.cplusplus.com/doc/tutorial/variables/
http://www.cplusplus.com/doc/tutorial/operators/

I highly recommend you look through that stuff before posting any more questions. These should be the first things you learn when using C++.
@cPlusN00b:
 you must specify a return var type (int in this case, void may work too)

This is a big NO NO, void main() is Illegal in C++, it may have worked in C, but in C++ the assembler translation for void main() is very different from that of int main() which can lead to unnoticeable errors with your program, which go along with not having a return value as it is often necessary for correct debugging to notice if main returned a non-zero or zero value. It is a bad habit that some C programmers use. Never Ever Use void main()
Last edited on
@007: Well noted! thanks
Topic archived. No new replies allowed.