Question

In: Computer Science

Write a C program that performs the following: Asks the user to enter his full name...

Write a C program that performs the following: Asks the user to enter his full name as one entry. Asks the user to enter his older brothers’ names each at a time (the user should be instructed by the program to enter NULL if he does not have any older brother). Asks the user to enter his younger brothers’ names each at a time (the user should be instructed by the program to enter NULL if he does not have any younger brother). Displays the user’s full name on the screen. Displays on the screen the following statement: “You are the eldest son” if the user has no older brothers but still he has younger ones, or Displays on the screen the following statement: “You are the youngest son” if the user has no younger brothers but still he has older ones, or Displays on the screen the following statement: “You are the only son” if the user does not have any brothers. Instructions: You should add a comment at the beginning of the program that shows your full name and student ID. You should use nested if else statement in the code.

Solutions

Expert Solution

//This program is devoloped using Codeblocks IDE.
#include <stdio.h>

int main()
{
//Declaring variables to store user's name and his/her olser and younger brothers' name

char uname[50],obroname[50],ybroname[50];
printf("Enter you full name: ");//Displaying message to enter user's full name.
scanf("%s",&uname);// Input user's Full name

printf("\nEnter you older brothers' name (Enter NULL if you do not have any older brother): ");
scanf("%s",&obroname); // Input older brothers' name

printf("\nEnter you younger brothers' name (Enter NULL if you do not have any younger brother): ");
scanf("%s",&ybroname);//Input younger brothers' name

printf("Your Full name is %s\n",uname); //Displaying user's Full name

//Using nested if
if(strcmpi(obroname,"NULL")==0) //Check whether the user has any younger brother
{
if(strcmpi(ybroname,"NULL")==0) //Check whether the user has any younger brother
{
printf("You are the only son"); //Display this message if the user has no older brother and no younger brother
}
if(strcmpi(ybroname,"NULL")!=0)
{
printf("You are the eldest son");
}
}
else
{
if(strcmpi(obroname,"NULL")!=0)
{
if(strcmpi(ybroname,"NULL")==0)
{
printf("You are the youngest son"); //Display this message if the user has no older brother but has younger ones
}
}
}
return 0;
}//End of main().

/*

OUTPUTS :-

*/


Related Solutions

Write a program that asks the user to enter the name of a file, and then...
Write a program that asks the user to enter the name of a file, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the file. Use Notepad or another text editor to create a sample file that can be used to test the program. Sample Run java FileLetterCounter Enter file name: wc4↵ Enter character to count: 0↵ The character '0' appears in the file...
Write a C++ program that asks the user to enter the monthly costs for the following...
Write a C++ program that asks the user to enter the monthly costs for the following expenses incurred from operating your automobile: loan payment, insurance, gas, oil, tires, and maintenance. The program should then display the total monthly cost of these expenses, and a projected total annual cost of these expenses. Label each cost. The labels should be left aligned and have a column width of 30 characters. The cost should be aligned right and displayed with two decimal places...
In.java Write down a program that asks the user for their full name given in the...
In.java Write down a program that asks the user for their full name given in the format first last. The program will do the necessary processing and print the name in a table with 3 columns: Last, First, Initials. Requirements/Specifications... Your program run must be identical with the one shown as an example (both in how it reads the input and it on what it prints). The table must have the top and bottom lines as shown. The columns for...
Tail of a File, C++ Program. write a program that asks the user for the name...
Tail of a File, C++ Program. write a program that asks the user for the name of a text file. The program should display the last 10 lines, or all lines if less than 10. The program should do this using seekg Here is what I have so far. #include<iostream> #include<fstream> #include<string> using namespace std; class File { private:    fstream file;    string name; public:    int countlines();    void printlines(); }; int File::countlines() {    int total =...
Write a C program that loops and asks a user to enter a an alphanumeric phone...
Write a C program that loops and asks a user to enter a an alphanumeric phone number and converts it to a numeric one. No +1 at the beginning. You can put all code in one quiz1.c file or put all functions except main in phone.c and phone.h and include it in quiz1.c Submit your *.c and .h files or zipped project */ #pragma warning (disable: 4996) //windows #include <stdio.h> #include <string.h> #include <stdbool.h> #include <ctype.h> enum { MaxLine =...
C++ write a program that asks the user to enter the hours and rate then calculate...
C++ write a program that asks the user to enter the hours and rate then calculate the gross pay for an employee, the program should test if the hours are regular (40), any hour more than 40 should be paid with the overtime rate: 1.5*rate. The program should ask repeatedly the user if he/she wants to continue: y or n, if the user types y, then the program should ask for the hours and rate for another employee then display...
write a program in c++ that asks the user to enter their 5 test scores and...
write a program in c++ that asks the user to enter their 5 test scores and calculates the most appropriate mean. Have the results print to a text file and expected results to print to screen.
In the space provided below write a C++ program that asks the user to enter their...
In the space provided below write a C++ program that asks the user to enter their quarterly earnings for the past two years stores the data in a 2-dimensional array. The program then computes both the annual earnings as well as the total earning and prints the results along with the 2-dimensional array on screen as well as onto a file.
Write a Python program that asks the user to enter a student's name and 8 numeric...
Write a Python program that asks the user to enter a student's name and 8 numeric tests scores (out of 100 for each test). The name will be a local variable. The program should display a letter grade for each score, and the average test score, along with the student's name. Write the following functions in the program: calc_average - this function should accept 8 test scores as arguments and return the average of the scores per student determine_grade -...
Design and implement a C++ program that performs the following steps:Ask the user to enter a...
Design and implement a C++ program that performs the following steps:Ask the user to enter a positive integer number N; Your program may need to prompt the user to enter many times until it reads in a positive number;Let user to enter N (obtained in the previous step) floating point numbers, and count how many positive ones there are in the sequence and sum up these positive numbers; (Hint: negative numbers or 0 are ignored).Display result.You can and should use...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT