Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Please help with this program (http://www.go4expert.com/forums/help-program-t28697/)

pers 9Jul2012 15:48

Please help with this program
 
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;

}

xpi0t0s 10Jul2012 13:21

Re: Please help with this program
 
>>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.


All times are GMT +5.5. The time now is 11:17.