00:00
00:00

## C++: Main

33,669 Views | 137 Replies

Response to C++: Main 2009-10-29 21:06:37

Hey C++. i've got a question with decimals. I'm just starting out with C++ and i'm trying to code a program that will calculate simple interest.

The Simple interest equation is I = PRT
I = Interest
P = Principal (starting amount)
R = Interest rate (percentage)
T = Time in years.

Interest rate has to be a decimal number when it's being calculated. For example, if I had 5.4% interest, i'd have to plug it into a calculator as 0.054.

How can I change the output to put decimal places in so I dont have to have a user input it as a decimal?

Response to C++: Main 2009-10-30 10:42:27

This is my code, if my previous post was unclear.

// Financial calculator

#include <iostream>
using namespace std;

int main()
{
long Interest, Principal, Time;
float Rate;

cout << "What was the principal payment?" << endl;
cin >> Principal;

cout << "What's the interest rate?" << endl;
cin >> Rate;

cout << "How many years?" << endl;
cin >> Time;

Interest = Principal * Rate * Time;

cout << "The amount of interest you'll have earned will be \$"<< Interest << endl << endl;

system("PAUSE");
return 0;
}

For a test input I enter the Principal as \$4500, the Rate as 9.5%, and the Time at 6 yrs. The outcome is \$256500. Is there a way for me to change the output from \$256500 to \$2565.00?

Response to C++: Main 2009-10-31 00:05:35

For a test input I enter the Principal as \$4500, the Rate as 9.5%, and the Time at 6 yrs. The outcome is \$256500. Is there a way for me to change the output from \$256500 to \$2565.00?

printf ("\$%.02f", value / 100.) ;

Response to C++: Main 2009-10-31 21:33:33

At 10/31/09 12:05 AM, thingie-348 wrote:

For a test input I enter the Principal as \$4500, the Rate as 9.5%, and the Time at 6 yrs. The outcome is \$256500. Is there a way for me to change the output from \$256500 to \$2565.00?
printf ("\$%.02f", value / 100.) ;

Thanks a lot!

Response to C++: Main 2010-10-12 14:19:32

Can I still contribute? I can write an SDL tutorial for displaying images on the screen.

Response to C++: Main 2010-10-12 15:01:45

Why now...Go for it I say!

PHP Main :: C++ Main :: Java Main :: Vorsprung durch Technik

irc.freenode.net #ngprogramming

Response to C++: Main 2010-10-12 18:45:24

Since I didn't know this little topic existed, I'll throw down a little tutorial I wrote a while back for creating a DLL in C++ and then reading that DLL in any other .NET language. The webpage is fairly boring at the moment, but the article is golden =)

Enjoy <3

http://afome.com/cplusplusdll.php

Response to C++: Main 2010-10-13 00:40:00

Is C++ incredibly popular? I know most of the syntax, I took a course for it last year and because I'm a CompSci major in college my first Computing class is learning C. I'm searching (halfheartedly, I guess) around to find which is the most common programming language that game engines are coded in so I can get a head start and start perfecting my knowledge of the language.

Obviously not talking about flash games, here, lol.

wew

Response to C++: Main 2010-10-14 13:52:02

At 10/13/10 12:40 AM, Trunks wrote: Is C++ incredibly popular? I know most of the syntax, I took a course for it last year and because I'm a CompSci major in college my first Computing class is learning C. I'm searching (halfheartedly, I guess) around to find which is the most common programming language that game engines are coded in so I can get a head start and start perfecting my knowledge of the language.

Obviously not talking about flash games, here, lol.

Yeah, C++ is kind of the standard for games but it is VERY similar to C.
I don't mean Visual basic 6 and VB7 similar (that it only works in theory), but in theory every C code is compatible with C++ and that goes as far as entire frameworks that were written in C work in C++ without any kind of adjustment (like OpenGL).

Response to C++: Main 2010-10-14 14:22:32

Just wrote displaying an image with SDL.

It belongs to Beginner: specific.

Response to C++: Main 2010-10-14 15:08:20

At 10/14/10 01:52 PM, Wolfos wrote: Yeah, C++ is kind of the standard for games but it is VERY similar to C.
I don't mean Visual basic 6 and VB7 similar (that it only works in theory), but in theory every C code is compatible with C++ and that goes as far as entire frameworks that were written in C work in C++ without any kind of adjustment (like OpenGL).

Yeah, that's why c is very easy for me, because I know the syntax of c++. It's annoying going backwards in time, though, because c++ to me seems like optimized c (which, i guess, it kind of is). So I guess c++ is going to be my new forte :D

wew

Response to C++: Main 2010-11-11 09:44:12

I've added a C tutorial! :)

C: Hello, World!

Response to C++: Main 2010-11-17 16:05:00

At 11/11/10 09:44 AM, UnknownFear wrote: I've added a C tutorial! :)

C: Hello, World!

It's called C++: Main for a reason...
In C++, main() should be an int.

Response to C++: Main 2010-11-18 13:19:34

At 11/17/10 04:05 PM, Wolfos wrote: It's called C++: Main for a reason...
In C++, main() should be an int.

Well excuse me for writing my C tutorial... in C instead of C++. The main page of this thread clearly states you can write C tutorials as well.

Response to C++: Main 2010-11-26 07:13:30

At 11/18/10 01:19 PM, UnknownFear wrote:
At 11/17/10 04:05 PM, Wolfos wrote: It's called C++: Main for a reason...
In C++, main() should be an int.
Well excuse me for writing my C tutorial... in C instead of C++. The main page of this thread clearly states you can write C tutorials as well.

My apologies then, for not fully reading the main page.

Response to C++: Main 2010-11-26 18:42:39

At 11/26/10 07:13 AM, Wolfos wrote: My apologies then, for not fully reading the main page.

It's all good. That may be the only C tutorial I will write if anyone else cares to.

Response to C++: Main 2011-02-15 10:54:08

Response to C++: Main 2011-12-12 11:30:27