Thread: C++ help

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2010
    Posts
    1
    Rep Power
    0

    Thumbs up C++ help


    This is what i need to do.

    *NO PASS BY REFERENCE CAN BE USED, ONLY VALUES*
    Write a C program to aid the Michigan Bookstore in estimating its business for next quarter. Experience has shown that sales depend on whether a book is required or suggested, and on whether or not it has been used before. A new, required book will sell to 90% (.90) of expected enrollment, but if it has been used before only 65% of the expected enrollment will buy it. Similarly, 40% of the expected enrollment will buy a newly suggested book, but only 20% will purchase a previously suggested book.

    INPUT
    Your program is to prompt the user for:
    - the book's 10 digit ISBN number as 10 separate characters
    - the list price per copy
    - the expected class enrollment
    - code of 'R'for required text or code of 'S' for suggested text
    - code of 'N' for a new text or code of 'O' for a text that has been used the previous quarter

    CALCULATE
    Calculate the number of copies needed and the profit if the store pays 80% of list (use global define for this). Use one to function to calculate number of books, one function to calculate the profit, and one function to output.

    OUTPUT A sample run might look like this:

    Enter book number: 0755798652
    Enter price per copy: 34.98
    Enter expected class enrollment: 31
    Enter 'R' if required or 'S' if suggested: r
    Enter 'N' if new or 'O' if not a new text: O

    ISBN: 0-75-579865-2
    Copies Needed: 20
    Profit: $ 146.92


    This is what i have


    Code:
    #include<stdio.h>
    
    //declare functions
    void inputData(char, char, char, char, char,
    			   char, char, char, char, char,
    			   float, int, char, char);
    void output(char, char, char, char, char, 
    			char, char, char, char, char,
    			int, float);
    int main(void)
    {
    	//declare variables
    	char n_1;
    	char n_2;
    	char n_3;
    	char n_4;
    	char n_5;
    	char n_6;
    	char n_7;
    	char n_8;
    	char n_9;
    	char n_10;
    	float price;
    	int enrollment;
    	char R_S;
    	char N_O;
    	int copies;
    	float profit;
    
    
    
    	//Input
    	n_1=inputData();
    	n_2=inputData();
    	n_3=inputData();
    	n_4=inputData();
    	n_5=inputData();
    	n_6=inputData();
    	n_7=inputData();
    	n_8=inputData();
    	n_9=inputData();
    	n_10=inputData();
    	inputData(price, enrollment);
    	R_S=inputData();
    	N_O=inputData();
    
    	//Calculations
    
    	//Output
    	output(n_1, n_2, n_3, n_4, n_5, n_6, n_7,
    			n_8, n_9, n_10, copies, profit);
    
    	return 0;
    }///End Main///////////////////////////////
    
    void inputData(char n_1, char n_2, char n_3, char n_4, char n_5, 
    			   char n_6, char n_7, char n_8, char n_9, char n_10,
    			   float price, int enrollment, char R_S, char N_O)
    {	
    	//Prompt user for necessary information
    	printf("Enter book number: ");
    	scanf(" %c %c %c %c %c %c %c %c %c %c", 
    		&n_1, &n_2, &n_3, &n_4, &n_5, &n_6, &n_7, &n_8, &n_9, &n_10);
    	
    	printf("Enter price per copy: ");
    	scanf("%.2f", &price);
    
    	printf("Enter expected class enrollment: ");
    	scanf("%f", &enrollment);
    	
    	printf("Enter 'R' if required or 'S' if suggested: ");
    	scanf(" %c", &R_S);
    	
    	printf("Enter 'N' if new or 'O' if not a new text: ");
    	scanf(" %c", &N_O);
    	
    	return ;
    }
    
    void output(char n_1, char n_2, char n_3, char n_4, char n_5, 
    			char n_6, char n_7, char n_8, char n_9, char n_10,
    			int copies, float profit)
    {
    	
    	
    	printf("ISBN: %c - %c %c - %c %c %c %c %c %c - %c", 
    		&n_1, &n_2, &n_3, &n_4, &n_5, &n_6, &n_7, &n_8, &n_9, &n_10);
    	printf("Copies Needed: %d", &copies);
    	printf("Profit: %f", &profit);
    
    	return;
    
    }
    What am i missing or need to add/fix? thanks in advanced
  2. #2
  3. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,117
    Rep Power
    1803
    Originally Posted by Ramenen
    - the book's 10 digit ISBN number as 10 separate characters
    An array of 10 characters, is still 10 separate characters, and much simpler to handle.
    Originally Posted by Ramenen
    What am i missing or need to add/fix? thanks in advanced
    Test it against the specification and tell us what does not work - that is what is missing or needs fixing. Once you have figured that out, ask more specific questions if you remain stuck. Don't make us review/test your code unnecessarily.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2010
    Posts
    3
    Rep Power
    0

    Use Chracter Array instead of using 10 different character variables.


    You can use Character array for storing 10 characters . You can access each character by its index easily. Why are you using 10 different character variables.

IMN logo majestic logo threadwatch logo seochat tools logo