•  Need help with writing an algorithm:
•  Department Store Sale! Prompt the user to enter the sticker price of each of the clothing items they’re purchasing (make sure all input prices are positive). The user should be allowed to purchase as many items as he or she would like. For each          individual item, the user should input whether the item is a White Tag (regular price), Blue Tag (25% off), Orange Tag (50% 
•  off), or Red Tag (75% off) item. Output the final bill, including tax. 
•  I'm new to this.





•  •  Main ()
•           Declare Tax_Price as Real
•           Declare Final_Price as Real
•           Declare Discount as Real
•           Declare Item_Price as Real
•           Display “Please enter the item price”
•           Input Item_Price
•           Display “Please enter discount as decimal”

Numeric input example (works with C or C++):

// a function to clean up the input of a real number

#include <stdio.h>   // in/out function header
#include <ctype.h>   // for isdigit()
#include <string.h>  // for strlen()

#define  EOS  0      // end of string marker

double real_in(void);

int main()
{
  double db;

  printf("\n Enter a mixed number eg. $12.45 (zero to exit): \n");
  while(1) {
    db = real_in();
    printf("\n Numeric part of input = %f\n",db);
    if (db == 0)
      return 0;
  }
  getchar();  // wait
  return 0;
}

// bulletproof entry of real numbers
double real_in(void)
{
  static char  s1[25], s2[25];
  int k, n = 0;

  printf("\n Enter a number : ");
  gets(s1);
  for (k = 0; k < strlen(s1); k++)
    if (isdigit(s1[k]) || s1[k] == '.' || s1[k] == '-') {
      s2[n] = s1[k];
      n++;
    }
  s2[n] = EOS;
  return (atof(s2));   // convert string to float
}

A strictly C++ example for numeric input:

// enter a price of 0.0 or higher (positive value)

#include <iostream>
#include <limits>

int main()
{
  float price = 0.0;

while ((std::cout << "Enter the price: ")
         && (!(std::cin >> price) || price < 0.0)) {
    std::cout << "That's not a positive value! ";
    std::cin.clear();
    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
  }

  std::cout << "You entered a price of " << price << "\n";

  return 0;
}
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.