i have a piece of an unfinished program.
try to run it...
if you go straight to option 3 and input values, how do i output these values in option 4 ?
i tried outputting my declared variables
it wont work ? why is this ?
i apologize the code is so long

I hope someone can tell me how i'd go about it

#include <iostream>  				//the usual headers are used including string
#include <string>
#include <conio.h>

void WeeklySales(); 									//these are functions i created
void yesnofunc();

main()
{
	int number; 													// declare variables
   char answer;
   double sales, sales_amount, quantity, total_sales, vat, commission;

   sales = (sales_amount * quantity);  				//initialise variables
   total_sales = (sales + vat);

   do {                   							//start of a do-while loop
   	      			//output displays the menu
   	cout << "\n\n******Sales System******";
      cout << ("\n\n");
      cout << "1. Display Company Logo.\n"; endl;
      cout << "2. Input/Validate weekly sales data.\n";endl;
      cout << "3. Calculate weekly sales.\n";endl;
      cout << "4. Display reciept.\n";endl;
      cout << "5. SHUT DOWN & LOG OFF.\n";endl;
		cout << "\nEnter a number...\n";endl;  //prompts the user

      cin >> number;
      cout << ("\n\n");

      switch (number)  //<--the expression is a variable (number) & controls
            //the switch the value of (number) is tested against a list of
            //constants. When a match is found, the statement sequence
            //assosciated with that match is executed.
               {
      				case 1:    //<-----  const = 1

     //displays the company logo
            			cout << "\n\tUU\tUU \tEEEEEEEE \tLL\t\t \SSSSSSS\n\tUU\tU";
                     cout << "U \tEE \t\tLL\t\tS\n\tUU\tUU \tEE \t\tLL\t\tS\n\t";
                     cout << "UU\tUU \tEEEEEEE \t\LL\t\t\ SSSSSS\n\tUU\tUU \tEE";
                     cout << " \t\tLL\t\t       S\n\tUU\tUU  \tEE  \t  \t\LL  ";
                     cout << "\t\t       S \n\t UUUUUUUU   *\tEEEEEEEE  *\tLLLLL";
                     cout << "LL  *\tSSSSSSS   *\n\n\n\n\n";

   //the break statement causes program flow to exit from the entire switch statement
                     break;

            		case 2:

            			cout << ("\nWeekly sales data\n\----------------- ");

                                break;

            		case 3:

            			cout << ("\nCalculate weekly sales \n\n");
                  	cout << "\n\nWould you like to calculate the weekly sales ? \n";
   						cin >> answer;

        //a switch within a switch
   						switch (answer)	{
         					case 'n':       //<---if 'n' is entered the text is ouputted
               				cout << "\n\n\nThank You!\n\n";
               				break;  //<----break takes it out of the switch
            				case 'y':  //<---if 'y' then program is run below

            //variables declared
   			double sales, sales_amount, quantity, total_sales, vat;
				total_sales = sales + vat;

   			cout << "\n\nTOTAL SALES = sales amount * quantity\n" << endl;
				cout << "\nEnter the sales amount\n";
				cin >>  sales_amount;
				cout << "\nEnter the quantity\n" ;
				cin >>  quantity ;
				sales = (sales_amount * quantity);
				cout << "\n" << sales_amount << "  *  " << quantity << " = " << sales << "\n";
				cout << "\n" << "Sales is: \t" << sales << "\n";
   			vat = 0.175*sales;
   			total_sales = (sales + vat);
				cout << "\nTOTAL SALES inc VAT is: \t" << total_sales << "\n";

				if(total_sales<25)
					cout << " and No commission";
				else if(total_sales<50)
					cout << "\n5% commission of total sales is " << 0.05 * total_sales ;
				else if(total_sales<75)
					cout << "\n10% commission of total sales is " << 0.10 * total_sales;
				else if(total_sales>75)
					cout << "\n20% commission of total sales is " << 0.20 * total_sales;
	}
                                break;
            		case 4:
//how would i display total sales and sales entered above in case 3 ?
            			cout << ("\nDisplay receipt \n\n");
                     cout << "\nUELS\n";
   						cout << "----\n\n";
                     cout << total_sales << "\n";   <-------------------i only get an address and not the output from case 3
                     cout << sales;

                     break;

            		case 5:

            			cout << ("\nGoodbye, and thank you for using U.E.L.S. \n\n");break;

                  //default statement sequence is executed if no matches are found
            		default:

            			cout << ("Enter a number from 1-5 only!\n\n\n\n\n\n");

         		}
      	} while (number !=5); //program will NOT stop looping till 5 is entered
      getch();
   }

void yesnofunc()
{
	char answer;

do {
		cout << "\nIs this correct ?\n";
   	cin >> answer;

   	switch (answer) {
      	case 'y':
         	cout << "\nThank you!!\n";
            break;

      }
	}while (answer != 'y');
}

i guess i'm trying to say; how do i output values from one case within a switch statement to another ?

double sales, sales_amount, quantity, total_sales, vat;

Your redeclaration is not in the scope of the main function .

i have a piece of an unfinished program.
try to run it...

No. If you post readable code, we can follow it. Please format your code cleanly and consistently. See this.

if you go straight to option 3 and input values, how do i output these values in option 4 ?
i tried outputting my declared variables
it wont work ? why is this ?

By not declaring them only during option 3. Once option 3 is done, the variables are destroyed. Define them at the beginning of main() .

i apologize the code is so long

Then just post the relevant section of code. Then, no need to be sorry, and we don't have to search so much. :icon_wink:

thanks

No. If you post readable code, we can follow it. Please format your code cleanly and consistently. See this.


By not declaring them only during option 3. Once option 3 is done, the variables are destroyed. Define them at the beginning of main() .


Then just post the relevant section of code. Then, no need to be sorry, and we don't have to search so much. :icon_wink:

thanks

ok, i have reformatted my code and sorted out my issue. For all those who were unhappy.
I now have a new problem, how would i output the commission value in case 4? (line 107).
here i have tried using

cout << "\n5% commission of total sales is " << commission = 0.05 * total_sales << "\n\n\n";

to assign commission a value, but i get the error

illegal use of floating point.

Any ideas?

Info :Compiling E:\program\kyeiassignforinternet.cpp
Warn : string.h(549,3):Functions containing for are not expanded inline
Warn : string.h(557,3):Functions containing while are not expanded inline
Warn : string.h(563,3):Functions containing for are not expanded inline
Warn : string.h(575,3):Functions containing for are not expanded inline
Warn : string.cc(686,32):Comparing signed and unsigned values
Warn : kyeiassignforinternet.cpp(14,10):Possible use of 'sales_amount' before definition
Warn : kyeiassignforinternet.cpp(14,10):Possible use of 'quantity' before definition
Warn : kyeiassignforinternet.cpp(15,16):Possible use of 'vat' before definition
Error: kyeiassignforinternet.cpp(90,103):Illegal use of floating point
Error: kyeiassignforinternet.cpp(92,104):Illegal use of floating point
Error: kyeiassignforinternet.cpp(94,104):Illegal use of floating point
Warn : kyeiassignforinternet.cpp(133,16):Use qualified name to access member type 'std::string'

oh yeah, here is my new and improved program:

#include <iostream>  				//the usual headers are used including string
#include <string>
#include <conio.h>

void WeeklySales(); 									//function i created


main()
{
  int number; 													// declare variables
  char answer;
  double sales, sales_amount, quantity, total_sales, vat, commission;

  sales = (sales_amount * quantity);  				//initialise variables
  total_sales = (sales + vat);
  commission = 0.05 * total_sales;
  commission = 0.10 * total_sales;
  commission = 0.20 * total_sales;

  do {                   							//start of a do-while loop
   	      			//output displays the menu
   	cout << "\n\n******Sales System******";
      cout << ("\n\n");
      cout << "1. Display Company Logo.\n"; endl;
      cout << "2. Input/Validate weekly sales data.\n";endl;
      cout << "3. Calculate weekly sales.\n";endl;
      cout << "4. Display reciept.\n";endl;
      cout << "5. SHUT DOWN & LOG OFF.\n";endl;
		cout << "\nEnter a number...\n";endl;  			//prompts the user

      cin >> number;                     //input
      cout << ("\n\n");

      switch (number)  //<--the expression is a variable (number) & controls
            //the switch the value of (number) is tested against a list of
            //constants. When a match is found, the statement sequence
            //assosciated with that match is executed.
               {  //<-----------start of the main switch
      			  case 1:    //<-----  const = 1

     //displays the company logo
                   cout << "\n\tUU\tUU \tEEEEEEEE \tLL\t\t \SSSSSSS\n\tUU\tU";
                   cout << "U \tEE \t\tLL\t\tS\n\tUU\tUU \tEE \t\tLL\t\tS\n\t";
                   cout << "UU\tUU \tEEEEEEE \t\LL\t\t\ SSSSSS\n\tUU\tUU \tEE";
                   cout << " \t\tLL\t\t       S\n\tUU\tUU  \tEE  \t  \t\LL  ";
                   cout << "\t\t       S \n\t UUUUUUUU   *\tEEEEEEEE  *\tLLLLL";
                   cout << "LL  *\tSSSSSSS   *\n\n\n\n\n";

   //the break statement causes program flow to exit from the entire switch statement
                   break;

            	  case 2:   //<------const = 2. if match found, executes,
                           //then calls the weeklysales function below

            		 cout << ("\nWeekly sales data\n\----------------- ");
                   WeeklySales();  //<-------------   function call here
                   break;

            	  case 3:

            		 cout << ("\nCalculate weekly sales \n\n");
                   cout << "\n\nWould you like to calculate the weekly sales ? y/n\n";
   					 cin >> answer;

        //a switch within a switch
   					 switch (answer) {

         					case 'n':       //<---if 'n' is entered the text is ouputted
               				cout << "\n\n\nThank You!\n\n";
               				break;  //<----break takes it out of the switch

            				case 'y':  //<---if 'y' then program is run below
				               cout << "\n\nTOTAL SALES = sales amount * quantity\n" << endl;
				               cout << "\nEnter the sales amount\n";
				               cin >>  sales_amount;
				               cout << "\nEnter the quantity\n" ;
				               cin >>  quantity ;

				               sales = (sales_amount * quantity);
				               cout << "\n" << sales_amount << "  *  " << quantity << " = " << sales << "\n";
				               cout << "\n" << "Sales is: \t" << sales << "\n";

   			               vat = 0.175*sales;
   			               total_sales = (sales + vat);
				               cout << "\VAT is :\t  " << vat << "\nTOTAL SALES inc VAT is: \t" << total_sales << "\n";

				               if(total_sales<=25)
					               cout << " and No commission";
				               else if(total_sales<=50)
					               cout << "\n5% commission of total sales is " << commission = 0.05 * total_sales << "\n\n\n";
				               else if(total_sales<=75)
					               cout << "\n10% commission of total sales is " << commission = 0.10 * total_sales << "\n\n\n";
				               else if(total_sales>75)
					               cout << "\n20% commission of total sales is " << commission = 0.20 * total_sales << "\n\n\n";
	                }     //<-------end of the switch statement within the switch statement (nested)
                           break;
            	  case 4:      //displaying the invoice

            		 cout << ("\nDisplay receipt \n\n");
                   cout << "\nUELS INVOICE\n";
   					 cout << "------------\n\n";
                   cout << "Sales Amount :   " << sales_amount << "\n";
                   cout << "Quantity :       " << quantity << "\n";
                   cout << "Sales :          " << sales << "\n";
                   cout << "VAT :            " << vat << "\n";
                   cout << "Total Sales :    " << total_sales << "\n";
                   cout << "Commission :     " << commission << "\n";  //<------------------i couldn't figure out how to calculate the commission
                   cout << "\n\n\n\n\n";
                   break;

            	  case 5:

            		 cout << ("\nGoodbye, and thank you for using U.E.L.S. \n\n");break;

         //default statement sequence is executed if no matches are found
            	  default:

            		 cout << ("Enter a number from 1-5 only!\n\n\n\n\n\n");

         		}    // <-----end of the main switch
     } while (number !=5); //<--end of do while loop. (program will NOT stop looping till 5 is entered)

  getch();

} // <---------end of main



void WeeklySales() //<--------weekly sales function not part of main() function
{                  //when function is completed, goes back to case 3:
//declare variables
	int sales_code, bikeprice, model_code, quantity;
   string date;
   char answer; //either yes or no

   cout << "\n\nWould you like to input weekly sales data ? \n";
   cin >> answer;
   	switch (answer)	{  //<--------start of main switch
         	case 'n':
               cout << "\n\n\nThank You!\n\n";
               break;
            case 'y':
   				do
        //the instructions to enter the i.d. code will be repeated (do...while
        //loop) as long as the sales_code is less than 1 or greater than 20.
   	            {

      	           cout << "\n\nPlease enter your identifiction code \n";
                    cin >> sales_code;

         //the condition is tested
                    if (sales_code < 1 || sales_code > 20)

         	          {
            	         cout << ("\nTHIS I.D. CODE IS NOT VALID. TRY AGAIN \n");
                      }
                   }
	//the instructions to enter the i.d. code will be repeated (do...while
   //loop) as long as the salescode is less than 1 or greater than 20.
                      while (1 > sales_code || sales_code > 20);

   //another do...while loop
               do
   	            {
      	           cout << "\nPlease enter the bike price (one unit = 1 Euro) \n";
      	           cin >> bikeprice;

                    if (bikeprice < 1 || bikeprice > 500)

         	          {
            	         cout << ("\nINVALID PRICE. Bike prices cannot be 0 or more than 500. TRY AGAIN \n");
                      }
                  }

                    while (bikeprice < 1 || bikeprice > 500);

   //another do...while loop
               do
   	            {
      	           cout << "\nPlease enter the 3 digit model code \n";
      	           cin >> model_code;

                    if (model_code < 0 || model_code > 999)

         	          {
            	         cout << ("\nINVALID MODEL CODE. TRY AGAIN \n");
                      }
                  }

                    while (model_code < 0 || model_code > 999);

   //another do...while loop
               do
   	            {
                    cout << ("\nPlease enter the quantity sold \n");
      	           cin >> quantity;

                    if (quantity < 1 || quantity > 10)

                      {
         	            cout << ("\nINVALID QUANTITY. TRY A NUMBER FROM 1-10 \n");
                      }
                  }

                    while (quantity < 1 || quantity > 10);

	            do
                  {

                	  cout << "\nPlease enter the date in this format dd/mm/yyyy: \n";
                    cin >> date;

			           cout << "\nIs this the correct date ?\t" << date << "\tpress y/n: \n\n";
                    cin >> answer;   //gets answer from user

			           switch (answer)	{
         	           case 'y':
            	           cout << "\n\n\nThank You!\n\n";
                          break;
                          }

                   }  while (answer != 'y');

            } //<---end of main switch statement

i dunno, when i post my code on here it changes up.
Trust me i reformatted it. :p

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.