Write C program YOU MUST NOT Use global variables YOU MUST NOT Use the word goto
ID: 3703242 • Letter: W
Question
Write C program
YOU MUST NOT Use global variables
YOU MUST NOT Use the word goto
YOU MUST NOT Use the break command outside a case statement
DO NOT ignore comments
Here is the outline,, complete
/*
“REQUIRED”
You must have a menu that loads information, stores information in an array(s)
Everything written in functions
Prohibit user from incorrect choices
Must include loops,switches,and decision statements
*/
#include
#include
#define _CRT_SECURE_NO_WARNINGS
#define CLS system(“cls”)
#define PAUSE system(“pause”)
#define SIZE 1000
//Prototype Directives---
void displayMenu();
char getChoice();
Int getWeight();
Int main() {
char choice;
Int weight [SIZE] = { 0 };
int i = 0;
do {
choice = getChoice();
switch (choice) {
Case1: '1'; // asks for weight
break;
Case2: '2'; //
break;
Case3: '3'; //gives average, high and low of weights
break;
Case4: '4'; //
break;
Case5: 'Quit'; // Quit the program
break;
default:
printf("Invalid Choice");
PAUSE;
break;
}//end switch
} while (choice != 'Q');
}//end main
void displaymenu(){
CLS;
printf(“1.Enter Weight ”);
printf(“2. Display Average of weights”);
printf(“3. Display Lowest Weights”);
printf(“4.
printf(“5.
printf(“6. Search ”);
printf(“7. Quit ”);
}//end displayMenu
char getChoice() {
char result;
displayMenu();
scanf_s("%c", &result);
return toupper(result);//Make it an Uppercase letter
}//end getChoice
Int result;
int getWeight(){
printf(“Enter Weight/n: “);
scanf_s(“%i”, &result);
return result;
}//end getWeight
//int n, i ;
Float [SIZE] , sum=0.0 , average;
printf(“Enter the Average/n ”)
scanf(“%d”, &n);
While (n > 1000 || n < = 1 )
{
}
2nd
//***********************************************************************************************************
#define PAUSE system("pause")
#define CLS system("cls")
#define SIZE 1000
#define _CRT_SECURE_NO_WARNINGS
#include
#include
//PROTOTYPE FUNTIONS HERE******
double averageWeight(double getWeights, double weights[10]);
void displayMenu();
int getChoice();
double getWeights();
int main() {
char choice;
float grades[SIZE] = { 0 };
int count = 0;
do {
choice = getChoice();
switch (choice) {
case 1: // asks for weights
getWeights();
break;
case 2: // gives average of weights
averageWeight(double getWeights, double weights[10]);
break;
case 3: //adds weights together and stores them in array
break;
case 4:
break;
case 5:
break;
case 6: //Quit the program
return 0;
break;
default:
break;
}//end switch
} while (choice != 'Q');
PAUSE;
}//end main
double averageWeight(double getWeights, double weights[10]) { //******************
int weights, i;
double total = 0.0, average;
for (i = 0; i < 5; i++) {
total += weights[i];
}//end of loop
average = total / 5;
printf("The average rainfall is %.2lf ", average);
PAUSE;
}//end averageWeight
void displayMenu() {//****************
CLS;
printf("1. ");
printf("2. ");
printf("3. ");
printf("4. ");
printf("5. ");
printf("6. ");
}//end displayMenu
int getChoice() {//*****************
int result;
displayMenu();
scanf_s("%i", &result);
return result;
}//end getChoice
double getWeights() {//***************
double weights[10] = { 0.0 };
int i;
for (i = 0; i < 10; i++) {
printf("Enter a weight amount for person %i: ", i + 1);
scanf_s("%lf", &weights[i]);
}//end for
}//end getWeights
PerfectOka Poor Your Pts [Comments Theme for Program Design Tool Comments and Documentation Look and Feel Functions Array Use Passing Arravs Sort Function Searching Arrays Error Checkin Menu System Program does something that makes sense 4 4 4 4 10 10 10 10 4 4 4 4 Total Pts 100Explanation / Answer
#include <stdio.h>
//PROTOTYPE FUNTIONS HERE******
void averageWeight(double *weights);
void sortWeights(double weights[10]);
void lowestWeight(double weights[10]);
void searchWeight(double weights[10]);
double askForWeight();
void displayMenu();
int getChoice();
double *getWeights();
int main() {
char choice;
double *weights;
do {
choice = getChoice();
switch (choice) {
case '1': // asks for weights
weights = getWeights();
break;
case '2': // gives average of weights
averageWeight(weights);
break;
case '3': //Gives the lowest Weight
lowestWeight(weights);
break;
case '4': //Displays the sorted weights
sortWeights(weights);
break;
case '5': // Checks whether a given weught is present or not
searchWeight(weights);
break;
default:
break;
}//end switch
} while (choice != 'Q');
}//end main
void averageWeight(double *weights) { //******************
double total = 0.0, average;
for (int i = 0; i < 10; i++) {
total += weights[i];
}//end of loop
average = total / 5;
printf("The average weight is %.2f ", average);
}//end averageWeight
void lowestWeight(double weights[10]) { //******************
double lowest_w = 9999999999.0;
for (int i = 0; i < 10; i++) {
if(lowest_w > weights[i])
{
lowest_w = weights[i];
}
}//end of loop
printf("The lowest weight is %.2f ", lowest_w);
}
void sortWeights(double weights[10]) { //******************
double a;
for (int i = 0; i < 10; ++i)
{
for (int j = i + 1; j < 10; ++j)
{
if (weights[i] > weights[j])
{
a = weights[i];
weights[i] = weights[j];
weights[j] = a;
}
}
}
printf("The sorted weights are ");
for(int i=0;i<10;i++){
printf("%f ", weights[i]);
}
}
double askForWeight()
{
double weight;
printf("Enter the weight you want to search: ");
scanf(" %lf", &weight);
return weight;
}
void searchWeight(double weights[10])
{
double weight;
weight = askForWeight();
printf("%f", weight);
int present = 0;
for (int i = 0; i < 10; i++) {
if(weight == weights[i])
{
present = 1;
}
}//end of loop
if(present == 1)
{
printf(" Given Weight is present in the weights array. ");
}
else
{
printf(" Given Weight is not present in the weights array. ");
}
}
void displayMenu() {//****************
printf("1. Enter Weight ");
printf("2. Display Average of weights ");
printf("3. Display Lowest Weights ");
printf("4. Sort all Weights ");
printf("5. Search ");
printf("Q. Quit ");
}//end displayMenu
int getChoice() {//*****************
char result;
char all_choices[6] = {'1', '2', '3', '4', '5', 'Q'};
displayMenu();
scanf(" %c", &result);
int correct_choice = 0;
for(int i=0; i<6; i++)
{
if(result == all_choices[i])
{
correct_choice = 1;
}
}
if(correct_choice != 1)
{
printf("Enter a correct choice. ");
return getChoice();
}
else
{
return result;
}
}//end getChoice
double* getWeights() {//***************
double *weights = malloc(10);
double weight;
int i;
for (i = 0; i < 10; i++) {
printf("Enter a weight for person %i: ", i + 1);
scanf("%lf", &weight);
weights[i] = weight;
}//end for
return weights;
}//end getWeights
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.