Question
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
a. 100 A 98.6
b. February 23 March 19
c. 19, 25, 103.876
d. A a B b
e. $56.45
Answers
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.
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.
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;
}
Related Questions
Write a function for the input-output table.
Input x- 0, 1, 2, 3
Output 7- 3, 4, 5, 6
Write a program that will input an item’s wholesale cost and its markup percentage.
The program w...
Write a code segment that inputs an integer from cin, and then outputs a row of that many stars on c...
Write a pseudocode to input 10 temperatures per day for 20 days and output the average per day and a...
Write a program that input two numbers and find if second number is square of firs number
Write a java program to input an integer numbers and find the highest number among them (using array...
Write a java program to input the ages of '10'students and count the number of students who has the...
Introduction the declarations of independence
Declarations of the Council of Trent 1545-1563:
1. Only the Catholic Church's interpretation of the...
input
Input Output Arrow
divide by 5,
then add 3
Input Output Arrow
output
Input Output
3...