Thread: Can i have some help with an assigment

  1. #1
    Registered User
    Join Date
    May 2020
    Posts
    17

    Can i have some help with an assigment

    Hi everyone,
    i need help to write a modular c program that accepts 5 user scores on a PS4 gaming console.

    the program must repeatedly request from each user, ratings on the following factors of PS4 gaming console

    • cost
    • games
    • backward compatibility
    • screen resolution



    all factors are to be stored using a scale of 1-5 where 5 being the highest rating. all 4 factor scores must be totaled and stored within the PS4_ScoringArray, giving a score out of 20 for each user.


    Write 3 functions to achieve the following requirements of the program.

    1. print the lowest score for the PS4 console
    2. print the hightest score for the PS4 console
    3. calculate and print the average of the scores for the PS4 console. Determines and print the average ratings on the PS4 console.

    a. "Excellent" if the average is between 16-20
    b. "Average" if the average is between 10-15
    c."Poor" if the average is between 0_9



    THANK YOU GUYS SO MUCH IN ADVANCE

    r

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    You need to show us what you can manage for yourself, and then we help you get past whatever block there is in your knowledge.

    Just dumping your assignment doesn't work.
    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
    May 2020
    Posts
    17
    I’m really at a loss at what to do for this assignment 😔 usually I’m able to read my books and figure it out but this time I’m not lucky that’s why I came here

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    A development process

    You need to learn to break the problem down into achievable steps. Just staring at the list of things to do and just hoping to visualise the entire answer in one keyboard session just doesn't happen.


    So start with printf and scanf to do this - once.

    the program must request from each user, ratings on the following factors of PS4 gaming console

    • cost
    • games
    • backward compatibility
    • screen resolution

    Then you do it 5 times
    i need help to write a modular c program that accepts 5 user scores
    Then you think about each stats in turn.
    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.

  5. #5
    Registered User
    Join Date
    May 2020
    Posts
    17
    #include <stdio.h>
    int main ()
    {
    int score, rating
    printf ("Please enter score")

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Like this.
    Code:
    printf("User 1\n");
    printf("What is your score for the cost of a PS4?");
    scanf("%d",&rateCost);
    At least try and post something that compiles next time.

    I'm assuming that you've actually written programs before this one.
    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.

  7. #7
    Registered User
    Join Date
    Apr 2020
    Posts
    4
    is there a way here to "likes " people replies. ? is there a like button

  8. #8
    Registered User
    Join Date
    Aug 2019
    Location
    inside a singularity
    Posts
    308
    On here, no. A simple "Thanks" does the work (but don't spam). Also, please don't post unrelated content in other threads.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook, The Wizardry Compiled

  9. #9
    Registered User
    Join Date
    Apr 2020
    Posts
    4
    THANK YOU Zeus

  10. #10
    Registered User
    Join Date
    May 2020
    Posts
    17
    Code:
    include <stdio.h>
    int score=0
    int userid=input
    for (loop 4 times)
    {
        Score+=userid
    }
    list int ids
    list int scores
    ids.add(id)
    scorea.add(score)
    list int ids
    list int scores 
    onlyinput=TRUE
    
    
    while (only input==true){
        int score=0
        int userid=input
        for (loop 4 times)
        {
            Score +=userid
        }
        if (id !=-1){
            ids.add(id)
            Scorea.add(score)
        }
        else{
            onlyinput=FALSE
            
            
        }
        }
        }
    }

  11. #11
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > usually I’m able to read my books and figure it out
    Well you should be at the stage where you can figure out what compiles and what doesn't.

    How do we identify in your pseudo code anything related to your question in post #1 ?

    Do this:
    Code:
        cost
        games
        backward compatibility
        screen resolution
    Do this, just once.
    4 printfs of suitable prompts
    4 scanfs into 4 meaningful variable names.
    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.

  12. #12
    Registered User
    Join Date
    May 2020
    Posts
    17
    Code:
    #include <stdio.h>
    
    main(){
        int Rating;
        printf ("Enter rating for cost");
        scanf("%d",&Rating);
        
        printf ("Enter rating for games");
        scanf("%d",&Rating);
        
        printf ("Enter rating for backward compatibility");
        scanf("%d",&Rating);
        
        printf ("Enter rating for screen resolution");
        scanf("%d",&Rating);
        
        
    }

    Ive been taking baby steps

  13. #13
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Good so far, but you want 4 separate variables.
    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.

  14. #14
    Registered User
    Join Date
    May 2020
    Posts
    17
    Code:
     
    #include<stdio.h>
    void rating_msg();
    void rating( );
    void lowest_rating();
    void highest_rating();
    void total_score();
    void average_score();
    
    int user_scores[5];
    int total ;
    
    int main(){
    	 int user[5], cost, games, bCompat, resolution, sum, lowest, highest;
    	 
    	 for(int i=0; i<3;i++){
    	 	
    	printf("User %d\n", i+1);
    	
    	rating_msg();// print msg function
    	
    	printf("Cost>>\t");
    	scanf("%d",&cost);
    	
    	if(cost>5){
    		printf("Invalid Rating! \nPlease Choose Again");
    			}
    			
    	printf("\nGames>>\t");
    	scanf("%d", &games);
    
    	if(games>5){
    		printf("Invalid Rating! \nPlease Choose Again");
    			}
    		
    	printf("\nBackward Compatibility>>\t");
    	scanf("%d", &bCompat);
    	
    	if(bCompat>5){
    		printf("Invalid Rating! \nPlease Choose Again");
    			}
    			
    	printf("\nScreen Resolution>>\t");
    	scanf("%d",&resolution);
    	
    	if(resolution>5){
    		printf("Invalid Rating! \nPlease Choose Again");
    			}
    		
    	user_scores[i] = cost+games+bCompat+resolution;
    	
    	printf("\nTotal Score>> %d\n\n", user_scores[i]);
    		
    	 }
    	 
    	 
    	lowest_rating();
    	highest_rating();
    	total_score();
    	average_score();
    }
    
    void rating_msg(){
    	printf("Please Rate the PS5 console based on the following factors!\n");
    	printf("The Rating is between 1 and 5\n1 being the lowest rate\nand 5 being the highest.\n\n");
    }
    
    
    void highest_rating(){
    	
    		int max= -1, mxPos= -1;
    	
    		for(int i=0; i<3;i++){
    			if(user_scores[i] > max){
    				max= user_scores[i];
    				mxPos = i;
    			}
    		}
    	printf("\nHighest %d\n\n",user_scores[mxPos]);
    }
    
    void lowest_rating(){
    	
    		int min= 999, mnPos= 999;
    		
    		
    		for(int i=0; i<3;i++){
    			if(user_scores[i] < min){
    				min= user_scores[i];
    				mnPos = i;
    			}
    		}
    		
    printf("\nLowest %d\n\n",user_scores[mnPos]);
    }
    void total_score(){
    	
    	for( int i=0 ;i<3;i++){
    		
    	printf("\n\nTotalScore User%d:%d",i+1,user_scores[i]);
    	
    	total+=user_scores[i];
    	}//end of second for loop 
    		printf("\n\nTotal:\t %d",total);
    	
    }
    void average_score(){
    		float avg;
    		avg = total / 3;
    		printf("\n\nAverage Score:%0.2f",avg);
    	
    	if ( avg > 16 && avg <= 20){
    	
    			printf("\nAverage Rating--> Excellent");
    		}
    		
    	else if ( avg > 10 && avg <= 15){
    	
    		printf("\nAverage Rating--> Average");
    	
    		}else {
    			
    			
    			printf("\nAverage Rating--> Poor");
    		}
    		
    	
    	
    	}

    I got some help from school. But can you type this in a shorter and easier to understand way

  15. #15
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    To make this easier to understand:
    • Indent the code consistently. Right now there's some indentation, but it is rather inconsistent, so it is not as helpful as it could be.
    • Get rid of the global variables and make use of function parameters. In a trivial program like this, global variables don't make it significantly harder to understand your code, but it is nonetheless good practice to use function parameters instead, which will make it easier to understand your code since it is clearer what the functions operate on.


    To make this shorter:
    • Actually, shorter doesn't really matter. What's more useful is to avoid repeating yourself, e.g., by moving repeated code into loops or functions, or replacing code with library function calls (which I guess isn't so much repeating yourself rather than repeating what's already done, but it is the same idea).
    • Use blank lines to separate function definitions and logical sections of code within a function definition. So this could make your code longer (with the positive effect of increasing readability), but it can also make your code shorter: remove blank lines that don't serve this purpose.


    A few other things to take note of:
    • Check the return value of scanf to ensure that the input really was read successfully.
    • When you display an error message due to an input error, you probably either want the user to try again, or you want to terminate the program. It makes no sense to inform the user but continue with the invalid input anyway.
    • This declares a function that takes an unknown number of parameters (from the perspective of the compiler at this point):
      Code:
      void rating_msg();
      What you wanted to do is declare it as taking no parameters:
      Code:
      void rating_msg(void);
      You should do the same for the function definition for consistency, but recall my earlier comment about using function parameters instead of global variables.
    Last edited by laserlight; 06-08-2020 at 03:59 PM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. question about assigment
    By mouse666666 in forum C Programming
    Replies: 11
    Last Post: 01-12-2011, 06:24 PM
  2. Help for my assigment
    By cloverdagreat in forum C Programming
    Replies: 16
    Last Post: 11-21-2009, 12:18 PM
  3. While assigment?
    By Fenix in forum C Programming
    Replies: 2
    Last Post: 08-24-2009, 07:35 AM
  4. Assigment
    By anonytmouse in forum A Brief History of Cprogramming.com
    Replies: 34
    Last Post: 05-07-2004, 11:25 AM
  5. Help on Assigment!!!!!!!!!!
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 04-05-2002, 09:07 PM

Tags for this Thread