could you correct this code. there are some errors #include <iostream> #include
ID: 3685675 • Letter: C
Question
could you correct this code. there are some errors
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <stdlib.h>
using namespace std;
//Take the number of pizzas desired * the size and return
float Bill(int NumPizzas, int Size)
{
float price = 0;
switch(Size)
{
case 1: price = 6.99 * NumPizzas;
break;
case 2: price = 8.99 * NumPizzas;
break;
case 3: price = 10.99 * NumPizzas;
break;
default:
cerr << " Oops, invalid size. Let's start over ";
exit(0);
break;
}
return price;
}
//Display options, collect order, show price and pick-up area
int main (void)
{
printf(" Welcome to the World's Worst Vegan Pepperoni Pizza Shop ");
printf(" Prices: $6.99 (S), $8.99 (M), $10.99 (L) ");
printf("Available sizes: Small = 1, Medium = 2, Larg = 3 ");
printf("Please enter size: ");
char sizeStr[4];
fgets(sizeStr, 4, stdin);
int size = atoi(sizeStr);
//Checking size not negative number or zero
if(size > 3 or size <1)
{
cerr << "Gotcha! Try again! ";
exit(0);
}
char buff[10];
printf("Enter the number of pizzas you wish to purchase: ");
fgets(buff, 10, stdin);
if (NumPizzas <0)
{
cerr >> "Please choose a valid number of pizzas ");
}
if (NumPizzas > 50)
{
cerr << "You can order up to fifty pizzas ";
exit(0);
}
float Price;
Price = Bill(NumPizzas, size);
char status[4];
ifstream statFile;
statFile.open("statusFile",ifstream::in);
statFile >> status;
status[3]='';
if (!strcmp(status, "111"))
{
printf("Thank you for your purchase! Your bill is: $%2.2f ",Price);
}
else
{
printf("Sorry, you have an outstanding balance, please contact the store to clear ");
}
return 0;
}
Explanation / Answer
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <stdlib.h>
using namespace std;
//Take the number of pizzas desired * the size and return
float Bill(int NumPizzas, int Size)
{
float price = 0;
switch(Size)
{
case 1: price = 6.99 * NumPizzas;
break;
case 2: price = 8.99 * NumPizzas;
break;
case 3: price = 10.99 * NumPizzas;
break;
default:
cerr << " Oops, invalid size. Let's start over ";
exit(0);
break;
}
return price;
}
//Display options, collect order, show price and pick-up area
int main (void)
{
printf(" Welcome to the World's Worst Vegan Pepperoni Pizza Shop ");
printf(" Prices: $6.99 (S), $8.99 (M), $10.99 (L) ");
printf("Available sizes: Small = 1, Medium = 2, Larg = 3 ");
printf("Please enter size: ");
char sizeStr[4];
fgets(sizeStr, 4, stdin);
int size = atoi(sizeStr);
//Checking size not negative number or zero
if(size > 3 or size <1)
{
cerr << "Gotcha! Try again! ";
exit(0);
}
char buff[10];
printf("Enter the number of pizzas you wish to purchase: ");
fgets(buff, 10, stdin);
int NumPizzas = atoi(buff);
if (NumPizzas <0)
{
cerr << "Please choose a valid number of pizzas ";
}
if (NumPizzas > 50)
{
cerr << "You can order up to fifty pizzas ";
exit(0);
}
float Price;
Price = Bill(NumPizzas, size);
char status[4];
ifstream statFile;
statFile.open("statusFile",ifstream::in);
statFile >> status;
status[3]='';
if (!strcmp(status, "111"))
{
printf("Thank you for your purchase! Your bill is: $%2.2f ",Price);
}
else
{
printf("Sorry, you have an outstanding balance, please contact the store to clear ");
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.