#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;
}
}

Please can you sort this out and repost it, Line 3 is saying unqualified-id before '{' token!!

Dani AI

Generated

The error is because a stray brace sits at file scope right after the includes, so the compiler expects a declaration but finds {. Also, calculateChange(int pay, int cost); in your "main" block is a declaration, not a call. A few other blockers: cin/setw need std:: (or using), your switch uses item instead of code, and units is never initialized. Building on what hinted and requested, here is a minimal, compiling skeleton you can drop in and expand.

#include <iostream>
#include <iomanip>
using std::cin; using std::cout; using std::endl; using std::setw;

void DisplayStoreItems();
int ChoosingItems();
int CalculateChange(int cost);

int main() {
    DisplayStoreItems();
    int cost = ChoosingItems();
    CalculateChange(cost);
    return 0; // no system("PAUSE") needed
}

void DisplayStoreItems() {
    cout << "Menu:\n"
         << "1 Bread(5)\n2 Oil(8)\n3 Pizza(43)\n"
         << "4 Laptop(1199)\n5 Macaroni(20)\n6 Tuna(7)\n";
}

int ChoosingItems() {
    int code = 0, cost = 0;
    for (;;) {
        cout << "Enter code (0 to finish): ";
        cin >> code;
        if (code == 0) break;
        switch (code) {
            case 1: cost += 5; break;    case 2: cost += 8; break;
            case 3: cost += 43; break;   case 4: cost += 1199; break;
            case 5: cost += 20; break;   case 6: cost += 7; break;
            default: cout << "Unknown code\n"; break;
        }
    }
    cout << "Total: " << cost << endl;
    return cost;
}

int CalculateChange(int cost) {
    int pay; cout << "Tendered: "; cin >> pay;
    int change = pay - cost;
    int hundreds = change / 100; change %= 100;
    int fifties  = change / 50;  change %= 50;
    int tens     = change / 10;  change %= 10;
    int ones     = change;
    cout << hundreds << " Hundreds\n" << fifties << " Fifties\n"
         << tens << " Tens\n" << ones << " Ones\n";
    return pay - cost;
}

Quick checklist:

  • Only declarations at global scope; put code inside int main() { ... }.
  • Calls never include types: use CalculateChange(cost);.
  • Qualify cin, cout, setw (or add using).
  • Use switch(code), not switch(item).
  • Replace the uninitialized units math with integer division/modulo as shown.

Recommended Answers

All 4 Replies

i dont have a compiler on this pc but as this is a common error i usually find the reason is because you dont have a matching pair of brackets
ie. you have a {
but no }
double check each { and make sure everyone has a } to go with it.
Im confident you will find you are missing one }

Remove the brace at line 3. You're just declaring functions, and that shouldn't be included in anything. Put int main() in front of the brace at line 10 and put a closing brace after the return 0.

sorry it still dont work

sorry it still dont work

Do you mind telling us what 'doesn't work' ? Post new code.

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.