Good! Read them, they will tell you what the problem is. That is what they are for. If you want help understanding them (which is fair enough), then post them. Learning to understand and interpret the error messages will be much more useful to you in the long term that just getting an answer to this specific question.
While function-like initialisation of basic types may work in C++ it is not very common to do that. I would generally avoid declaring a variable "long double" unless you know:
a) that you really need that level of precision,
b) that every compiler you will ever build your code with recognises the type,
c) that your compiler actually uses higher precision than for plain double (not all do, if you code relies on it, it will not be portable, and may fail).
The variable t does not exist where you have used it as an initialiser.
Read up on namespaces, and the std:: namespace in particular.
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm enrolled in an online class and I'm trying to figure this out as an assignment
Is there anything wrong with this code? I've made it from scratch but it keeps coming up with errors!
// number two on review 1.2
include <iostream>
include <string>
// variables
int num_Values;
float score;
long double size (16.34);
char flag (t);
// strings
int main ()
{
string name = "William";
cout << name << endl;
system("pause");
return 0;
}
> but it keeps coming up with errors!
Good! Read them, they will tell you what the problem is. That is what they are for. If you want help understanding them (which is fair enough), then post them. Learning to understand and interpret the error messages will be much more useful to you in the long term that just getting an answer to this specific question.
While function-like initialisation of basic types may work in C++ it is not very common to do that. I would generally avoid declaring a variable "long double" unless you know:
a) that you really need that level of precision,
b) that every compiler you will ever build your code with recognises the type,
c) that your compiler actually uses higher precision than for plain double (not all do, if you code relies on it, it will not be portable, and may fail).
The variable t does not exist where you have used it as an initialiser.
Read up on namespaces, and the std:: namespace in particular.
Clifford
Sorry, it should be compiling!
Please post your Basic 3. They are covered in the thread with the appropriate
title "Please Read Before Posting a Question"
One thing by the way that screams from your code. You are using functions
that are in the standard namespace, but you I see nothing like
using namespace std;
or qualifiers like
std::cout
Wayne
And what do you thing this line of code is doing?
char flag (t);
And note that the "system" function shoows up in
cstdlib
In short, no, your code should NOT compile, it has signiificant errors.
With the namespace problem addressed, the weird char line commented out, and cstdlib included, you code compiles and runs here.
Wayne