Thread: homework help intro to c

  1. #1
    Registered User
    Join Date
    Feb 2016
    Posts
    5

    homework help intro to c

    Hello I'm doing an app purchasing program and my setcost function will only print the the cost of one the apps for whatever I input. My program is not finished yet, so not all my function definitions have been defined. Thank you for your help.

    Code:
    #define _CRT_SECURE_NO_WARNINGS
    #include <stdio.h>
    #include <ctype.h>
    
    
    // Displays the list of apps available
    //prompts for the user’s selection and sets the value of the selection
    void DisplayApps(char *selectionPtr);
    
    
    //sets the cost of the item based on value stored in purchase
    void SetCost(char selection, double *costPtr);
    
    
    //Displays the codes for the user to input money - gets user input amounts
    //compares the int codes and updates the deposit amount
    void PaymentOptions(double *depositPtr, double cost);
    
    
    //compares the amount the user has in deposits to the price of app selected.
    //It returns 1 if the amount is enough to cover the cost, 0 if there is not enough.
    int Compare(double deposit, double choiceCost);
    
    
    //uses PaymentOptions function to display and collect dollar amounts from the user
    //uses Compare function to keep comparing the added deposited amount to the item cost.
    void Pay(double *depositPtr, double choiceCost);
    
    
    //calculates the amount of leftover from your deposits
    void GetChange(double *depositPtr, double choiceCost);
    
    
    //Asks the user if they want another app
    void DoItAgain(char *quitPtr);
    
    
    
    
    int main()
    {
    	char again, selection;
    	double cost;
    
    
    	printf("Welcome To The App Store\n");
    	printf("***********************************\n");
    	do {
    		// Amount of money
    		//Display the Apps
    		DisplayApps(&selection);
    		SetCost(selection, &cost);
    		printf("cost is %.2lf\n", cost);
    		DoItAgain(&again);
    	} while (again == 'Y');
    
    
    	return 0;
    }
    
    
    void DoItAgain(char *quitPtr)
    {
    	printf("Do you want to make another purchase?\n");
    	scanf(" %c", quitPtr);
    	*quitPtr = toupper(*quitPtr);
    }
    
    
    void DisplayApps(char *selectionPtr)
    {
    	printf("Here are your selections:\n\n");
    	printf("C -- Clown Punching         $299.99\n");
    	printf("V -- Virtual Snow Globe     $249.99\n");
    	printf("R -- Remote PC              $999.99\n");
    	printf("G -- Grocery List Helper    $2.99\n");
    	printf("M -- Mobile Cam Viewer      $89.99\n\n\n");
    	printf("Please enter a selection\n");
    	scanf(" %c", selectionPtr);
    	*selectionPtr = toupper(*selectionPtr);
    	printf("Your selection was: %c\n", *selectionPtr);
    	printf("-------------------------------------------------\n");
    }
    
    
    void SetCost(char selection, double *costPtr)
    {
    	if (selection = 'C')
    	{
    		*costPtr = 299.99;
    	 }
    	else if (selection = 'V')
    	{
    		*costPtr = 249.99;
    	}
    	else if (selection = 'R')
    	{
    		*costPtr = 999.99;
    	}
    	else if (selection = 'G')
    	{
    		*costPtr = 2.99;
    	}
    	else if (selection = 'M')
    	{
    		*costPtr = 89.99;
    	}
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    There is a difference between = and ==

    FWIW, a better compiler helps (or just adding options to the one you're using).
    Code:
    $ gcc -Wall main.c
    main.c: In function ‘SetCost’:
    main.c:88:2: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
      if (selection = 'C')
      ^
    main.c:92:2: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
      else if (selection = 'V')
      ^
    main.c:96:2: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
      else if (selection = 'R')
      ^
    main.c:100:2: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
      else if (selection = 'G')
      ^
    main.c:104:2: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
      else if (selection = 'M')
      ^
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Feb 2016
    Posts
    5
    Thank for your help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Intro to C programming help
    By bluebrandon in forum C Programming
    Replies: 3
    Last Post: 01-31-2012, 08:59 PM
  2. void Intro()
    By Inderjeet in forum C Programming
    Replies: 9
    Last Post: 07-05-2011, 02:55 PM
  3. Intro + help
    By D2k204 in forum C++ Programming
    Replies: 4
    Last Post: 07-30-2007, 02:17 PM
  4. MakeFile : intro
    By ylvawandel in forum Tech Board
    Replies: 2
    Last Post: 10-21-2005, 07:20 AM
  5. Intro to C++, NEED HELP!!!
    By romeoz in forum C++ Programming
    Replies: 14
    Last Post: 06-11-2003, 08:19 PM

Tags for this Thread