/*
*****************************************************************************
Workshop - #6 (P1)
Full Name :
Student ID#:
Email :
Section :
Authenticity Declaration:
I declare this submission is the result of my own work and has not been
shared with any other student or 3rd party content provider. This submitted
piece of work is entirely of my own creation.
*****************************************************************************
*/
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#define MAX_ITEMS 10
int main(void)
{
const float Maximum = 400000.00;
const float Minimum = 500.00;
printf("+--------------------------+\n");
printf("+ Wish List Forecaster |\n");
printf("+--------------------------+\n");
float netIncome = 0;
while (1) {
printf("Enter your monthly NET income: $");
scanf("%f", &netIncome);
if (netIncome < Minimum) {
printf("ERROR: You must have a consistent monthly income of at least $500.00\n");
printf("\n");
continue;
}
if (netIncome > Maximum) {
printf("ERROR: Liar! I'll believe you if you enter a value no more than $400000.00\n");
printf("\n");
continue;
}
break;
}
printf("\n");
int numberOfItems = 0;
while (1) {
printf("How many wish list items do you want to forecast?: ");
scanf("%d", &numberOfItems);
if (numberOfItems > MAX_ITEMS || numberOfItems<1) {
printf("ERROR: List is restricted to between 1 and 10 items.\n");
printf("\n");
continue;
}
break;
}
printf("\n");
float itemPrice[numberOfItems];
int priority[numberOfItems];
char choices[numberOfItems];
for (int i = 0; i < numberOfItems; i++) {
printf("Item-%d Details:\n", (i + 1));
while(1){
printf("\tItem Cost: $");
scanf("%f", &itemPrice[i]);
if (itemPrice[i] < 100) {
printf("\t\tERROR: Cost must be at least $100.00\n");
printf("\n");
continue;
}
break;
}
while (1) {
printf("\tHow important is it to you? [1=must have, 2=important, 3=want]:");
scanf("%d", &priority[i]);
if (priority[i] < 1 || priority[i]>3) {
printf("\t\tERROR: Value must be between 1 and 3\n");
continue;
}
break;
}
while (1) {
fseek(stdin, 0, SEEK_END);
printf("\tDoes this item have financing options? [y/n]:");
scanf("%c", &choices[i]);
if (choices[i] != 'y' && choices[i] != 'n') {
printf("\t\tERROR: Must be a lowercase 'y' or 'n'\n");
continue;
}
break;
}
printf("\n");
}
printf("Item Priority Financed Cost\n");
printf("---- -------- -------- -----------\n");
float total = 0;
for (int i = 0; i < numberOfItems; i++) {
printf("%3d %5d %5c %11.2lf\n", (i + 1), priority[i], choices[i], itemPrice[i]);
total += itemPrice[i];
}
printf("---- -------- -------- -----------\n");
printf(" $%11.2lf\n\n", total);
printf("\nBest of luck in all your future endeavours!");
return 0;
}