Course Hero Logo

w8p2.c - /* * Workshop - #8 (P2) Full Name : Preet Patel...

Course Hero uses AI to attempt to automatically extract content from documents to surface to you and others so you can study better, e.g., in search results, to enrich docs, and more. This preview shows page 1 - 3 out of 5 pages.

/******************************************************************************Workshop - #8 (P2)Full Name: Preet PatelStudent ID#: 175058213Email: [email protected]Section: NAAAuthenticity Declaration:I declare this submission is the result of my own work and has not beenshared with any other student or 3rd party content provider. This submittedpiece of work is entirely of my own creation.******************************************************************************/#define _CRT_SECURE_NO_WARNINGS// System Libraries#include<stdio.h>// User-Defined Libraries#include "w8p2.h"// ----------------------------------------------------------------------------// PART-1// 1. Get user input of int type and validate for a positive non-zero number//(return the number while also assigning it to the pointer argument)int getIntPositive(int* input){int a;scanf("%d",&a);while (a <= 0){printf("ERROR: Enter a positive value: ");scanf("%d",&a);}if(input != NULL){*input = a;}return a;}// 2. Get user input of double type and validate for a positive non-zero number//(return the number while also assigning it to the pointer argument)double getDoublePositive(double* input){double a;scanf("%lf",&a);while (a <= 0){printf("ERROR: Enter a positive value: ");scanf("%lf",&a);}if(input != NULL){*input = a;}
return a;}// 3. Opening Message (include the number of products that need entering)void openingMessage(const int products_analyse){printf("Cat Food Cost Analysis");printf("\n======================\n");printf("\nEnter the details for %d dry food bags of product data foranalysis.",max_products);printf("\nNOTE: A 'serving' is %dg\n",no_grams);}// 4. Get user input for the details of cat food productstruct catfoodinfo getCatFoodInfo(const int seq_no){struct catfoodinfo product;printf("\nCat Food Product #%d",seq_no);printf("\n--------------------");printf("\nSKU: ");product.skuno = getIntPositive(NULL);printf("PRICE: $");product.price = getDoublePositive(NULL);printf("WEIGHT (LBS): ");getDoublePositive(&(product.weight));

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 5 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Fall
Professor
N/A
Tags
Pointer, Return statement, Void type, scanf

Newly uploaded documents

Show More

Newly uploaded documents

Show More

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture