Question

In: Computer Science

Complete the following assignment in C programming language. Get the user’s first name and store it...

Complete the following assignment in C programming language.

  1. Get the user’s first name and store it to a char array
    • Declare a character array to hold at least 20 characters.
    • Ask for the user’s first name and store the name into your char array.
    • Hint: Use %s for scanf. %s will only scan one word and cannot scan a name with spaces.
  2. Get 3 exam scores from the user:
    • Declare an array of 3 integers
    • Assume the scores are out of 100, and use a for loop to get user’s input
    • Your prompts should print out which exam score you are asking for:
      1. Example: “What is the score of Exam #1?” … “What is the score of Exam #3?”
    • Warning: Be careful of your array indexes!
  3. Find out the average exam score:
    • Use a for loop to calculate the sum of all exams.
    • Divide the sum by 3 to get the average and store the is data in a variable.
  4. Print out the summary for the use similar to:
    • “Hello NAME, based on your exam score of 80, 90, and 100, your average is 90.0 with a letter of an ‘A.’”

Solutions

Expert Solution

Below is the code for the above question in C:

#include <stdio.h>

int main()
{
char first_name[20];
char name[20];
int exam_scores[3];
int sum = 0;
int i;
  
  
printf("Enter your name : ");
scanf("%s", first_name);
  
for (int j = 0; first_name[j] != '\0'; j++)
{
name[j] = first_name[j];
}
  

for(i = 1 ; i <= 3 ; i++)
{
printf("What is the score of Exam#%d? \n",i);
scanf("%d", &exam_scores[i]);
}
  
  
for(int i = 1 ; i <= 3 ; i++)
{
sum = sum+exam_scores[i];
}
  
float average = sum / 3;
  
printf("hello %s, based on your exam score of %d, %d, and %d, your average is %f with a letter of an ‘A.’",name,exam_scores[1],exam_scores[2],exam_scores[3],average);
  
return 0;
}

Screenshot :

Explanation :

In the above code first the user is prompted to enter his or her name followed by prompted to enter the marks 1 , marks 2, marks 3 . This is achieved by using the for loop for asking the user to enter the marks . Then using the for loop the marks are added and then divide by the constant 3 to calculate the average of the three marks . In the end the name and the average of the three marks are being displayed in the format mentioned in the question above .


Related Solutions

Complete the following assignment in C programming language. Get the user’s first name and store it...
Complete the following assignment in C programming language. Get the user’s first name and store it to a char array Declare a character array to hold at least 20 characters. Ask for the user’s first name and store the name into your char array. Hint: Use %s for scanf. %s will only scan one word and cannot scan a name with spaces. Get 3 exam scores from the user: Declare an array of 3 integers Assume the scores are out...
Complete the following assignment in C programming language. 1. Declare the following float variables: -Maximum exam...
Complete the following assignment in C programming language. 1. Declare the following float variables: -Maximum exam score, user's exam score, and percentage. 2. Ask the user to input data into your variables, such as: -"What is the max score of your exam:" -"What was your score:" 3. Use if statements to validate user inputs. For example, score received should not be more than maximum possible score. -Display an error message when the user enters invalid data. -You can restart the...
Objectives: 1. To get familiar with C# programming language 2. To get familiar with Visual Studio...
Objectives: 1. To get familiar with C# programming language 2. To get familiar with Visual Studio development environment 3. To practice on writing a C# program Task 1: Create documentation for the following program which includes the following: a. Software Requirement Specification (SRS) b. Use Case Task 2: Write a syntactically and semantically correct C# program that models telephones. Your program has to be a C# Console Application. You will not implement classes in this program other than the class...
Complete the following exercises using C programming language. Take screenshots of the code and its output...
Complete the following exercises using C programming language. Take screenshots of the code and its output where specified and paste them into in a well-labeled Word document for submission. Scenario Assume you are the CIO of an organization with three different IT department locations with separate costs. You want a program to perform simple IT expenditure calculations. Your IT expenditure target is $35,000 per site. Site expenditures: Site 1 – $35,000. Site 2 – $37,500. Site 3 – $42,500. Exercise...
Programming Language: C++ Overview For this assignment, write a program that will simulate a single game...
Programming Language: C++ Overview For this assignment, write a program that will simulate a single game of Craps. Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, or if the game continues. If the sum of the first roll of the dice is equal to 7 or 11, the player wins immediately....
Assignment (C language, not C ++) Start a new project to store grade information for 5...
Assignment (C language, not C ++) Start a new project to store grade information for 5 students using structures. Declare a structure called student_t that contains : First name Last name Student ID Number Percentage grade Letter grade Create the following functions: getStudentInfo(void)- Declares a single student object - Uses printf()/scanf() to get keyboard input for Name, SID, and Percentage (not Letter). - Returns a single student structure calcStudentGrade(student_t *st_ptr)- Takes the pointer to a student (to avoid making a...
In C/C++ programming language, write down the lines of codes (and figure) to show- a) assignment-by-sharing...
In C/C++ programming language, write down the lines of codes (and figure) to show- a) assignment-by-sharing b) dangling reference
C++ programming Complete the code to input and store all the information in the structure Book:...
C++ programming Complete the code to input and store all the information in the structure Book: title, author, year and pages. Complete the function print() with arguments and code to print a Book variable in the following format: Book title: <title> Book author: <name> Published in <year> Number of pages: <pages> #include <iostream> using namespace std; struct Book { string title; string author; string year; int pages; }; void print(/*arguments*/) { //Complete function } int main() { //Declare structure variable...
Using (C programming language) Create a health monitoring program, that will ask user for their name,...
Using (C programming language) Create a health monitoring program, that will ask user for their name, age, gender, weight, height and other health related questions like blood pressure and etc. Based on the provided information, program will tell user BMI, blood pressure numbers if they fall in healthy range or not and etc. Suggestions can be made as what should be calorie intake per day and the amount of exercise based on user input data. User should be able to...
Hi, I am working on an assignment in C-Programming language dealing with LInked lists, in the...
Hi, I am working on an assignment in C-Programming language dealing with LInked lists, in the code there is instructions on where to write the code. I do not know how to write Linked Lists. Has to be in the C-language, Any help is greatly appreciated   //agelink.c //maintains list of agents //uses linked list #include <stdio.h> #include <stdlib.h> #define TRUE 1 void listall(void); void newname(void); void delink(void); void memexit(void); void wfile(void); /********************************************************************* this is the structure to hold a agent...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT