HEre is my C++ program I made.... first I will put the directions and then the program. I cant seem to compile it for some reason so can anyone tell me what I did wrong please!!

Write a C++ program that does the following. Besides #include <iostream>, you will need #include <string>. Call this program program1.cpp

1. declare a char
2. declare an int
3. declare a float
4. declare a double
5. declare a string
6. declare a bool
7. assign values to each of these (separate statements from the declarations above)
8. print each variable to the monitor followed by an endline
9. assign a char to your int variable
10. print out that variable with statement like: “here is my char stored in an int variable”.
11. 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.
12. add the two ints together and divide the total by 2. Print that result to the screen with a statement like: “(x+y)/2 = “ followed by result and an endline.

#include <iostream>
#include <string>

using namespace std;

	char = 6
	int = 2
	float = 7
	double = 10
	string = 9
	bool = 12
	cout << char << endl;
	cout << "the value of char is " << char << endl;
	cout << int << endl;
	cout << "the value of int is " << int << endl;
	cout << float << endl;
	cout << "the value of float is " << float << endl;
	cout << double << endl;
	cout << "the value of double is " << double << endl;
	cout << string << endl;
	cout << "the value of string is " << string << endl;
	cout << bool << endl;
	cout << "the value of bool is " << bool << endl;
	cout << (char)int;
	cout << "Here is my char stored in an int 

	size of (int);
	size of (char);
	cout << size of (char) << endl;
	char = size of (char);
	size of (int);
	size of (int);
	cout << size of (int) << endl;
	int = size of (int);
	size of (int);
	size of (float);
	cout << size of (float) << endl;
	float = size of (float);
	size of (int);
	size of (double);
	cout << size of (double) << endl;
	double = size of (double);
	size of (int);
	size of (string);
	cout << size of (string) << endl;
	string = size of (string);
	size of (int);
	size of (bool);
	cout << size of (bool) << endl;
	bool = size of (bool);
	cout << "(x+y)/2 = " << (myint+myint2)/2 << endl;
	return 0;

Edited by Nick Evan: Added [CODE] .... [/CODE] tags

6 Years
Discussion Span
Last Post by NP-complete

There are so many errors in your code that it's pointless to even start pointing them out.

Why don't you just read the first few pages in your C++ book? They should tell you all you need to know to fulfill the task.


I totally agree with Aranarth. Friend you need to learn some basics of a language first before you take the plunge. So please, read up first before you start coding.
All the best


Haha, wow, wouldnt even know where to start, but I will give it a shot and rewrite it for ya =P

// Rewritten.cpp : Defines the entry point for the console application.

#include "stdafx.h"
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;


	char Character[32] =  "Cleaner";; 
	//Characters Only or sequence of characters seperated and stored in an array i.e: "H\e\l\l\o\\!"
	//May be single characters also i.e: a,b,c,d,e,f,g,h etc
	//Declare as "char Character" without square brackets( [] ), without square brackets will take in single characters

	int Integer = 69;       
	//integers only i.e: 1,2,3,4,5,6,7

	float Float = 0.5;
	//decimal float numbers or inherits a decimal value i.e: 0.5

	double Double = 3.14159;
	//Large decimal numbers or inherits a Large decimal value i.e: 3.14159265358979323846264..

	string String = "Cleaner Code";
	//String of characters i.e: "This is a string"

	 bool Boolean= "True";
	 //Value such as "True" or "False"

int _tmain(int argc, _TCHAR* argv[])
	cout << "The Value stored in      char: Character is -> " << Character << endl;
	cout << "The Value stored in       int: Integer   is -> " << Integer   << endl;
	cout << "The Value stored in     float: Float     is -> " << Float     << endl;
	cout << "The Value stored in    double: Double    is -> " << Double    << endl;
	cout << "The Value stored in    string: String    is -> " << String    << endl;
	cout << "The Value stored in      bool: Boolean   is -> " << Boolean   << endl << endl;

	//Note Size may change, whether bool be: True or False

	cout << "    Size of Character: " << sizeof(Character) << endl;
	cout << "      Size of Integer: " << sizeof(Integer) << endl;
	cout << "        Size of Float: " << sizeof(Float) << endl;
	cout << "       Size of Double: " << sizeof(Double) << endl;
	cout << "       Size of String: " << sizeof(String) << endl;
	cout << " Size of Boolean TRUE: " << sizeof(Boolean) << endl;

	return 0;
Good job helping this dude cheat...

Wow thanks for doing that for me. I had help from someone else and they gave me some information but obiously I did it completely wrong... I would like to know how you knew how to do this. I know it is probably a very simple thing to write for others but I am completely lost at how to go about ti. Is there anywhere you would recommend so that I might learn to do it or at least get more information about writing codes like this?? thanks so much!!


yeah bro ppl are right
there are so many errors..here..
perhaps u shud start from hte beginning ...

best of luck..


I'd start with a smaller "project" than the one you are trying to do right now.

Deal with 1 data type like an integer and try declaring it adding integers and printing them out to get a feel for the syntax, otherwise you will overwhelm yourself and end up with lots of errors and you will have no clue where to look.


@ parse :

Dont give out codes and that too codes that don't stick to the specs. For eg you were supposed to declare and initialize separately but you did them together.
Also, when the OP was asked to study and then come up with a better solution you should have perhaps waited for him to come up with a solution.
Your third post was far better (those links that you gave). In future try to help the OP with his learning don't just give out codes that he can simply copy paste for his HW. That's not daniweb.

Edited by NP-complete: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.