Discussion in 'C' started by pers, Jul 9, 2012.

1. ### persNew Member

Joined:
Jul 9, 2012
Messages:
1
0
Trophy Points:
0
Hey everyone, so I've done the most I could do, but I still don't know how to add string, bool, and char into this equation. Could you please help.

Here are the instructions:
1. declare a char, an int, 3 float, a double, a string and a bool.
2. assign values to each of these. This should be done in separate steps from the declaration.
3. print each variable to the monitor preceeded by a statement saying what you are printing. Example: “here is my char: “ << char;
4. for each variable, write a statement that will print it’s size to the monitor. The statement should say, “the size of x is: “ followed by variable, followed by an endline.
5. divide one float by another and put the result in the 3rd float. hint – you can reuse variables if you don’t need their value anymore. Print the result to the screen with a statement like: “x/y = “ x followed by an endline.
6. perform any other mathematic operations you feel like and print result to screen (but tell me what I’m seeing).

And here's what I've come up with so far:

#include <iostream>
using namespace std;
int main()

{

int i;
float x, y, z;
double d;

i = 15;
d = 40;
x = 25;
y = 125;
z = y/x;

cout << "Here's my int: " << 'i' << endl;
cout << "Here's my first float: " << 'x' << endl;
cout << "Here's my second float: " << 'y' << endl;
cout << "Here's my third float: " << 'z' << endl;
cout << "Here's my double: " << 'd' << endl;
cout << endl;

cout << "The size of my int is: " << i << endl;
cout << "The size of double is: " << d << endl;
cout << "The size of my first float, x, is: " << x << endl;
cout << "The size of my second float, y, is: " << y << endl;
cout << "The size of z, which is y/x, is equal to: " << z << endl;

return 0;

}

2. ### xpi0t0sMentor

Joined:
Aug 6, 2004
Messages:
3,009
203
Trophy Points:
63
Occupation:
Senior Support Engineer
Location:
England
>>I still don't know how to add string, bool, and char into this equation

Why not? You've figured it out for int:
Code:
```int i;
```
so clearly you know the format is TYPENAME VARIABLENAME SEMICOLON.

Have a wild guess at how you might declare a string and post the result.