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;
}
MOD EDIT: Added code tags. When posting code...USE CODE TAGS!!!
This post has been edited by JackOfAllTrades: 09 July 2012 - 03:13 AM

New Topic/Question
Reply



MultiQuote





|