Question

i need this written in C, not C++ or anything else, just C, thank you.

4. Name this program select.c-This program determines the results of a three-member selection committee that is picking the winner between two finalists. The program reads three strings (all of which are single words that are ten characters or less in length). Your program should print the winner (the string that occurred the most). You can assume that there are no more than two unique names in the input. In fact, all the names might be the same if the selection committees decision is unanimous. For example, entering BigAl and Aubie and BigAl gives a winner of BigAL

apparently this works, but I can't use this, hope this helps though:

#include<iostream>

#include<string.h>

using namespace std;

int main()

{

char finalist1[10], finalist2[10], winner[10];

char decision[3][10];

int count1=0,count2=0,i;

cout<<"Enter name of the first finalist: ";

gets(finalist1);

cout<<"\nEnter name of the second finalist: ";

gets(finalist2);

cout<<"\n\nEnter decision of the first committee member: ";

gets(decision[0]);

if(strcmp(decision[0],finalist1)==0 || strcmp(decision[0],finalist2)==0)

{

cout<<"\nEnter decision of the second committee member: ";

gets(decision[1]);

if(strcmp(decision[1],finalist1)==0 || strcmp(decision[1],finalist2)==0)

{

cout<<"\nEnter decision of the third committee member: ";

gets(decision[2]);

if(strcmp(decision[2],finalist1)!=0 && strcmp(decision[2],finalist2)!=0)

{

cout<<"\nInvalid name by third committee member!";

exit(1);

}

}

else

{

cout<<"\nInvalid name by second committee member!";

exit(1);

}

}

else

{

cout<<"\nInvalid name by first committee member!";

exit(1);

}

for(i=0;i<3;i++)

{

if(strcmp(decision[i],finalist1)==0)

count1++;

else

count2++;

}

if(count1>count2)

cout<<endl<<finalist1<<" is the winner!";

else

cout<<endl<<finalist2<<" is the winner!";

return 0;

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Dear Student,

here i have converted the given C++ into C program as per the requirement.

----------------------------------------------------------------------------------------------------------------------------------------

Note: Please note that the below program has been tested on ubuntu 16.04 system and compiled under gcc compiler. This code will also work on other IDE's.

------------------------------------------------------------------------------------------------------------------------------------------

Program:

------------------------------------------------------------------------------------------------------------------------------------------

#include<stdio.h>

#include<string.h>

#include<stdlib.h>

int main()

{

char finalist1[10], finalist2[10], winner[10];

char decision[3][10];

int count1=0,count2=0,i;

printf("Enter name of the first finalist: ");

gets(finalist1);

printf("\nEnter name of the second finalist: ");

gets(finalist2);

printf("\n\nEnter decision of the first committee member: ");

gets(decision[0]);

if(strcmp(decision[0],finalist1)==0 || strcmp(decision[0],finalist2)==0)

{

printf("\nEnter decision of the second committee member: ");

gets(decision[1]);

if(strcmp(decision[1],finalist1)==0 || strcmp(decision[1],finalist2)==0)

{

printf("\nEnter decision of the third committee member: ");

gets(decision[2]);

if(strcmp(decision[2],finalist1)!=0 && strcmp(decision[2],finalist2)!=0)

{

printf("\nInvalid name by third committee member!");

exit(1);

}

}

else

{

printf("\nInvalid name by second committee member!");

exit(1);

}

}

else

{

printf("\nInvalid name by first committee member!");

exit(1);

}

for(i=0;i<3;i++)

{

if(strcmp(decision[i],finalist1)==0)

count1++;

else

count2++;

}

if(count1>count2)

printf("%s is the winner.\n", finalist1);

else

printf("%s is the winner.\n", finalist2);

return 0;

}


------------------------------------------------------------------------------------------------------------------------------------------

here i have attached a sample run of the program as a screen shot...

--------------------------------------------------------------------------------------------------------------------------------------------------

Output:

-----------------------------------------------------------------------------------------------------------------------------------------------

Kindly Check and Verify tHANKS...!!!

Add a comment
Know the answer?
Add Answer to:
i need this written in C, not C++ or anything else, just C, thank you. apparently...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This is for a C++ program: I'm almost done with this program, I just need to...

    This is for a C++ program: I'm almost done with this program, I just need to implement a bool function that will ask the user if they want to repeat the read_course function. I can't seem to get it right, the instructions suggest a do.. while loop in the main function. here is my code #include <iostream> #include <cstring> #include <cctype> using namespace std; const int SIZE = 100; void read_name(char first[], char last[]); void read_course(int & crn, char des[],...

  • Hello, I am working on my final and I am stuck right near the end of...

    Hello, I am working on my final and I am stuck right near the end of the the program. I am making a Tic-Tac-Toe game and I can't seem to figure out how to make the program ask if you would like to play again, and keep the same names for the players that just played, keep track of the player that wins, and display the number of wins said player has, after accepting to keep playing. I am wanting...

  • There is a problem with thecode. I get the error messages " 'board' was not declared...

    There is a problem with thecode. I get the error messages " 'board' was not declared in this scope", \src\TicTacToe.cpp|7|error: expected unqualified-id before ')' token| \src\TicTacToe.cpp|100|error: expected declaration before '}' token| Here is the code #ifndef TICTACTOE_H #define TICTACTOE_H #include class TicTacToe { private: char board [3][3]; public: TicTacToe () {} void printBoard(); void computerTurn(char ch); bool playerTurn (char ch); char winVerify(); }; ************************************ TicTacToe.cpp #endif // TICTACTOE_H #include "TicTacToe.h" #include #include using namespace std; TicTacToe() { for(int i =...

  • -I need to write a program in C to store a list of names (the last...

    -I need to write a program in C to store a list of names (the last name first) and age in parallel arrays , and then later to sort them into alphabetical order, keeping the age with the correct names. - Could you please fix this program for me! #include <stdio.h> #include <stdlib.h> #include <string.h> void data_sort(char name[100],int age[100],int size){     int i = 0;     while (i < size){         int j = i+1;         while (j < size){...

  • I need help in my C++ code regarding outputting the enums in string chars. I created...

    I need help in my C++ code regarding outputting the enums in string chars. I created a switch statement for the enums in order to output words instead of their respective enumerated values, but an error came up regarding a "cout" operator on my "Type of Item" line in my ranged-based for loop near the bottom of the code. I tried casting "i.type" to both "i.GroceryItem::Section::type" and "i.Section::type", but neither worked. Simply put, if a user inputs 1 as their...

  • My if/else statement wont run the program that I am calling. The menu prints but once...

    My if/else statement wont run the program that I am calling. The menu prints but once I select a number the menu just reprints, the function called wont run. What can I do to fix this probelm? #include <iostream> #include "miltime.h" #include "time.h" #include "productionworker.h" #include "employee.h" #include "numdays.h" #include "circle.h" using namespace std; int main() { int select=1;     while (select>0) { cout << "Option 1:Circle Class\n"<< endl; cout << "Option 2:NumDay Class\n" << endl; cout <<"Option 3:Employee and Production...

  • I want to change this code and need help. I want the code to not use...

    I want to change this code and need help. I want the code to not use parallel arrays, but instead use one array of struct containing the data elements, String for first name, String for last name,Array of integers for five (5) test scores, Character for grade. If you have any idea help would be great. #include #include #include #include using namespace std; const int NUMBER_OF_ROWS = 10; //number of students const int NUMBER_OF_COLUMNS = 5; //number of scores void...

  • I need help solving this in c++ using visual Studio. For this assignment, you will be filling in missing pieces of code within a program, follow the comments in the code. These comments will describe...

    I need help solving this in c++ using visual Studio. For this assignment, you will be filling in missing pieces of code within a program, follow the comments in the code. These comments will describe the missing portion. As you write in your code, be sure to use appropriate comments to describe your work. After you have finished, test the code by compiling it and running the program, then turn in your finished source code. // TicTacToe.cpp: Follow along with...

  • My program works fine with if else conditions but when it is not working when I...

    My program works fine with if else conditions but when it is not working when I try to implement it using a for loop. Can you fix my for loop and please show me how to do this using loops? I would appreciate if you could explain the loop that you are using. /* Programming Challenge: Shipping Charges The Fast Freight Shipping Company charges the following rates: Weight of Package (in Kilograms) Rate per 500 Miles Shipped 2 kg or...

  • Need help with a C++ program. I have been getting the error "this function or variable...

    Need help with a C++ program. I have been getting the error "this function or variable may be unsafe" as well as one that says I must "return a value" any help we be greatly appreciated. I have been working on this project for about 2 hours. #include <iostream> #include <string> using namespace std; int average(int a[]) {    // average function , declaring variable    int i;    char str[40];    float avg = 0;    // iterating in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT