C++ help

It's good practice to not entirely depend on an IDE ;). Especially as a beginning programmer. In the beginning, you should be doing pretty much everything yourself. Then later, once you actually understand what's going on and how things work, then you can use advanced tools/features of IDE's.

And yes, I do use Visual Studio. And when I did C++ development, i used Code::Blocks.

I wasn't saying you should use your IDE as a crutch, I was just pointing out that if you forget it, it's not the end of the world. :p
 
I keep on getting an error C4700: uninitialized local variable 'interest' used. Does this mean I entered it wrong at the beginning? Am I suppose to use int instead of float? When I looked it up on google is said something about putting =0 which fixed the error but then I was unable to get the correct answer.....

float interest;

cout << "This is a interest calculator.Type in the principal?";
cin >> principal;
cout << "Type in your rate as a decimal";
cin >> rate;
cout << "Type in the years of saving";
cin >> time;
cout << "The interest is:" << interest << endl;
cin >> interest;
interest = (principal*rate*time) / 100;
cout << endl << endl;
 
Did you forget your main() method, or did you choose to omit it?

"uninitialized local variable 'interest' used." means you tried pulling a value from your 'interest' variable before you gave it one.

Code:
cout << "The interest is:" << interest << endl;

cin >> interest;

You're trying to output the value of "Interest" before the user sets it.
 
Last edited:
Did you forget your main() method, or did you choose to omit it?

"uninitialized local variable 'interest' used." means you tried pulling a value from your 'interest' variable before you gave it one.

Code:
cout << "The interest is:" << interest << endl;

cin >> interest;

You're trying to output the value of "Interest" before the user sets it.

This. You're using the variable before it has a value.
 
A big part of programming is interpreting debugging messages. Better to get good at it early on ;).
 
another noob question...sorry guys...but would these be considered named constants....centimeters = inches*2.54 .....I know that is technically a formula but I didn't know how else to put it....
 
No, those aren't constants.

Constants are just that - constants. Their values don't change. In C++ (and most other languages) you declare a value as a constant, as such:
Code:
const int MAX_SIZE = 20;
Then you cannot reassign the value - it's basically just a placeholder for a value. The value is replaced throughout the program during compile-time. It makes it easier so if you need to change the value, you only have to change it in 1 spot instead of multiple spots.

In the case of your formula... centimeters is a variable because the value isn't assigned at compile time (like constants are) - it's generated during run time (computed from user input), inches is a variable because it's value is assigned from the user during runtime.
 
Back
Top Bottom