#include <iostream>
#include <iomanip>
{
void DispalyStoreItems ();

int ChoosingItems ();

double calculateChange ( int , int );
{

	int cost;

	DispalyStoreItems ();

	cost = ChoosingItems ();

	calculateChange ( int pay , int cost );

	system ("PAUSE");

	return 0;

void DispalyStoreItems ()
{
	std::cout <<"Code" << setw (10) << "Item" << setw (10) << "Price" << endl;

	std::cout << "------------------------" << endl;

	std::cout << setw (2) << "1" << setw (13) << "Bread" << setw (7) << "5" << endl;

	std::cout << endl;

	std::cout << setw (2)  << "2" << setw (11) << "Oil" << setw (9) << "8" << endl;

	std::cout << endl;

	std::cout << setw (2) << "3" << setw (13) << "Pizza" << setw (8) << "43" <<endl;

	std::cout << endl;

	std::cout << setw (2) << "4" << setw (14) << "Laptop" << setw (9) << "1199" << endl;

	std::cout << endl;

	std::cout << setw (2) << "5" << setw (16) << "Macaroni" << setw (5) << "20" << endl;

	std::cout << endl;

	std::cout << setw (2) << "6" << setw (12) << "Tuna" << setw (8) << "7" << endl;

	std::cout << endl;
}
int ChoosingItems ()
{
	int price;
	int item = 0;
	int cost = 0;
	int code = 0;
	int Bread = 0;
	int Oil = 0;
	int Pizza = 0;
	int Laptop = 0;
	int Macaroni = 0;
	int Tuna = 0;

	while ( true )
	{
		std::cout << "Enter the code of the Item you want to buy : ";

		cin >> code;

		std::cout << endl;

		if ( code == 0 )
			break;

		switch ( item )
		{
			case 1:
				Bread++;
				break;

			case 2:
				Oil++;
				break;

			case 3:
				Pizza++;
				break;

			case 4:
				Laptop++;
				break;

			case 5:
				Macaroni++;
				break;

			case 6:
				Tuna++;
				break;
		}

		if ( code == 1 )
		{
			price = 5;
		}
		else if ( code == 2 )
		{
			price = 8;
		}
		else if ( code == 3 )
		{
			price = 43;
		}
		else if ( code == 4 )
		{
			price = 1199;
		}
		else if ( code == 5 )
		{
			price = 20;
		}
		else if ( code == 6 )
		{
			price = 7;
		}
		else
		{
			price = 0;
		}

		cost += price;
	}

	if ( Bread != 0 )
		std::cout << "The User Buys " << item << "\n";
	if ( Oil != 0 )
		std::cout << "The User Buys " << item << "\n";
	if ( Pizza != 0 )
		std::cout << "The User Buys " << item << "\n";
	if ( Laptop != 0 )
		std::cout << "The User Buys " << item << "\n";
	if ( Macaroni != 0 )
		std::cout << "The User Buys " << item << "\n";
	if ( Tuna != 0 )
		std::cout << "The User Buys " << item << "\n";

	std::cout << "and Pays " << cost << "\n";

	return cost;
}
double calculateChange ( int pay, int cost )
{
	double units;
	double change;

	std::cout << "Enter the amount of the money you should pay : ";

	cin >> pay;

	std::cout << endl;

	change = pay - cost;

	if ( change >= 100)
	{
		change = ( change / 100 ) - ( units * 100 );

		std::cout << change << "Hundreds" << "\n";
	}
	if ( change >= 50 )
	{
		change = ( change / 50 ) - ( units * 50 );

		std::cout << change << "Fifties" << "\n ";
	}
	if ( change >= 10 )
	{
		change = ( change / 10 ) - ( units * 10 );

		std::cout << change << "Tens" << "\n";
	}
	if ( change >= 1 )
	{
		change = change - units;

		std::cout << change << "Ones" << "\n";
	}

	return change;
}

If you put this into CodeBlocks, and see what has happened (Line 3)

William Hemsworth commented: No code-tags, crap title, badly presented question. -1

Recommended Answers

All 4 Replies

What happens? Soz I don't have CodeBlocks + I'm on my DSi.
Anyway, you could put:
using namespace std;
instead of putting:
std::cout...
all the time.
Also, do you need to declare the two void functions at the top, as they have nothing in them, and you declare them later.

Anyway, you could put:
using namespace std;
instead of putting:
std::cout...
all the time.

No you don't. That's the whole idea with namespaces: you don't just 'include' all the functions from it.
What if you have a second namespace (called mystd for example) which also has a cout function in it?
This is good:

std::cout << "hai";
mystd::cout << "bai";

But now your solution:

using namespace std;
using namespace mystd;

cout << "uh-oh, which function to choose??";

See the problem?

commented: Good suggestion. +6

On the whole namespace thing, yes, don't use namespaces, but you can do things like using std::cout; at the top of your program so you don't need to put the std:: in front of every print statement.

As for the OP, you asked no question, but your code is riddled with syntax errors, missing braces, etc. Look at the errors you get when you try to compile. Any half-way decent compiler will tell you what line the error is on, come back with specific questions and then we can help you.

double thread with this. Closed

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.