a.
use a String variable because we have an item "A".
In Java, it would be
String[] s={"100","A","98.6");
In C++, it would be similar,
string s[]={"100","A","98.6");
b.
will take a simple string variable, not an array.
c.
a float (in Java, C, C++, etc.)
d.
char variable in Java, C, C++.
e. In Visual basic, there is the currency variable.
In Java, C, C++, you could use float or double.
Write a declarations and input statements necessary to read each of the following sets of data values into variables of the appropriate types. You choose the names of the variables. In some cases, punctuation marks or special symbol must be skipped.
a. 100 A 98.6
b. February 23 March 19
c. 19, 25, 103.876
d. A a B b
e. $56.45
3 answers
For part a) I have this but is not compiling! What is wrong with this?
#include <iostream>
#include <string>
using namespace std;
int X = "100";
const string a; "A";
const float C; "98.6";
int main()
{
cout << "The sets of data is" << X a C << endl;
return 0;
}
#include <iostream>
#include <string>
using namespace std;
int X = "100";
const string a; "A";
const float C; "98.6";
int main()
{
cout << "The sets of data is" << X a C << endl;
return 0;
}
You're not far.
Remember any compiler will give you an error message to explain which line you have a problem, and what kind of problem it is.
Most compilers/editors allow you to display the line numbers to which the compilers list of error refer.
Proceed to resolve the problems one by one, according to the message.
The above program has some syntax errors, which are rather standard and easily corrected.
To give some hint, I will annotate at the end of the line.
#include <iostream>
#include <string>
using namespace std;
// I would put these lines after (i.e.
inside of) int main()
// if it is an integer, do not use " "
// just write int X=100;
// same for float, write const float C=98.6;
// for string, write in two lines
// string a;
// a="A";
int X = "100";
const string a; "A";
const float C; "98.6";
int main()
{
// need << bewteen X and a, and a and C
cout << "The sets of data is" << X a C << endl;
return 0;
}
Remember any compiler will give you an error message to explain which line you have a problem, and what kind of problem it is.
Most compilers/editors allow you to display the line numbers to which the compilers list of error refer.
Proceed to resolve the problems one by one, according to the message.
The above program has some syntax errors, which are rather standard and easily corrected.
To give some hint, I will annotate at the end of the line.
#include <iostream>
#include <string>
using namespace std;
// I would put these lines after (i.e.
inside of) int main()
// if it is an integer, do not use " "
// just write int X=100;
// same for float, write const float C=98.6;
// for string, write in two lines
// string a;
// a="A";
int X = "100";
const string a; "A";
const float C; "98.6";
int main()
{
// need << bewteen X and a, and a and C
cout << "The sets of data is" << X a C << endl;
return 0;
}