Posts

Showing posts with the label Score

In Java, Analyze Scores Given By User

Image
import java.util.Scanner; public class AnalyzeScores{ public static void main(String[]args){ int num, sum = 0, cnt = 0; int[]nums=new int[100]; Scanner in = new Scanner(System.in); System.out.print("Enter N numbers (-1 to quit): "); while(in.hasNextInt() && cnt < nums.length){ num = in.nextInt(); if(0 > num) break; nums[cnt++] = num; sum += num; } if(0 == cnt){ System.out.println("Error: No inputs given!"); return; } int avg = sum/cnt, abAvg = 0, blAvg = 0; for(int i = cnt-1; 0 <= i; i --) if(nums[i] >= avg) abAvg ++; else blAvg ++; System.out.printf("Nos# above avg: %d\n", abAvg); System.out.printf("Nos# below avg: %d\n", blAvg); } }

In C, Write A Function That Will Read A Collection Of Examination Scores

Image
Problem Statement Write a function that will read a collection of examination scores ranging in value from 1 to 100. Your subprogram should count and print the number of scores in the outstanding category ( 90 – 100), the number of scores in the satisfactory category ( 60-89), and the number of scores in the unsatisfactory category ( 1-59). #include<stdio.h> int read(int[], const int); void stats(int scores[], const int); int main(){ const int MAX_LEN = 20; int scores[MAX_LEN]; const int size = read(scores, MAX_LEN); stats(scores, size); return 0; } int read(int scores[], const int LEN){ int i = 0, n; do{ if(LEN <= i)break; printf("Enter score (-1 to stop): "); if(scanf("%d", &n)){ if(-1 == n)break; if(1 > n || 100 < n){ printf("Error: Invalid score!\n"); continue; } scores[i++] = n; } }whi...