Question

I was looking for help with a computer science c programming class. not c++ This program...

I was looking for help with a computer science c programming class. not c++

This program will have menu system. The menu will at least have the following options:

                        ***********************************************************

                        **                   MAIN MENU **

                        ***********************************************************

  1. Enter Votes from a state for Donald Trump
    • Choose State
    • Enter Number of Votes
  2. Enter Votes from a state for Joe Biden
    • Choose State
    • Enter Number of Votes
  3. Display total votes for each candidate
  4. List the state name(s) where candidate tied
  5. For each candidate display the highest and lowest votes
  6. Election is over, Exit Program

could someone please point me in the right direction

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

#include <stdio.h>

//structure for election info
struct Election
{
//stateNum will store the number of a state
//use an array for multi state election
int stateNum;
  
//use an array for multi state election
//each element will store the votes for a single state
int votes;
};

//funciton to display the state list
void stateList()
{
printf("\nPress 1: For California");
printf("\nPress 2: For Florida");
printf("\nPress 3: For Hawali");
}

int main()
{
struct Election candidate[2];
  
char stateStr[3][20] = {"California", "Florida", "Hawali"};
printf("Enter votes from a state for Donald Trump");
stateList();
printf("\n\nChoose State: ");
  
scanf("%d", &candidate[0].stateNum);
printf("\nEnter the number of votes: ");
scanf("%d", &candidate[0].votes);
  
printf("\nEnter votes from a state for Joe Biden");
stateList();
printf("\n\nChoose State: ");
  
scanf("%d", &candidate[1].stateNum);
printf("\nEnter the number of votes: ");
scanf("%d", &candidate[1].votes);
  
//display total votes
printf("\nTotal votes for Donald Trump: %d", candidate[0].votes);
printf("\nTotal votes for Joe Biden: %d", candidate[1].votes);
  
//display highest and lowest score
printf("\n\nThe lowest score for Donald Trump: %d", candidate[0].votes);
printf("\nThe highest score for Donald Trump: %d", candidate[0].votes);
printf("\n\nThe lowest score for Joe Biden: %d", candidate[1].votes);
printf("\nThe highest score for Joe Biden: %d", candidate[1].votes);
  
//check if candidate tie
if((candidate[0].votes == candidate[1].votes) && (candidate[0].stateNum == candidate[1].stateNum))
{
printf("\n\nCandidate tie in %s", stateStr[candidate[0].stateNum]);
}
  
return 0;
}

OUTPUT:

Enter votes from a state for Donald Trump
Press 1: For California
Press 2: For Florida
Press 3: For Hawali

Choose State: 2

Enter the number of votes: 20000

Enter votes from a state for Joe Biden
Press 1: For California
Press 2: For Florida
Press 3: For Hawali

Choose State: 2

Enter the number of votes: 20000

Total votes for Donald Trump: 20000
Total votes for Joe Biden: 20000

The lowest score for Donald Trump: 20000
The highest score for Donald Trump: 20000

The lowest score for Joe Biden: 20000
The highest score for Joe Biden: 20000

Candidate tie in Hawali

Add a comment
Know the answer?
Add Answer to:
I was looking for help with a computer science c programming class. not c++ This program...
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
  • Please post following code with criteria below... please leave as many comments as possible Exam Four:...

    Please post following code with criteria below... please leave as many comments as possible Exam Four: the election Outcome: Student will demonstrate all core competencies from this class: Program Design (design tools) Variables Decision Error Checking Looping Functions Arrays Program Specifications: Let’s pretend that we are tracking votes for the next presidential election. There will be two candidates: Ivanka Trump and Michele Obama. You can assume that there are fifty states casting votes. You will do not need to deal...

  • Assignment 11.2: New Hampshire Primary (10 pts) The New Hampshire Primary is taking place this Tuesday,...

    Assignment 11.2: New Hampshire Primary (10 pts) The New Hampshire Primary is taking place this Tuesday, February 11, 2020. According to Wikipedia, a primary "Primary elections or often just primaries, are the process by which voters can indicate their preference for their party's candidate, or a candidate in general, in an upcoming general election... with the goal of narrowing the field of candidates" The New Hampshire primary is the first of the primary elections, which will be held to select...

  • I was looking for help in my computer programming class. The program I need to create...

    I was looking for help in my computer programming class. The program I need to create is this. Program Specifications: Write a C program what will read in one word. Store this word in an array. Hint: char myWord[SIZE] = ‘ ‘; Once you store the word, you are to do the following four things: Display: The word is: abcdefg Display: The word backwards is: gfedcba Display: The word vertical is: A B C D E F G Display: The...

  • Using c++ Write a program that reads in a list of up to 25 first names...

    Using c++ Write a program that reads in a list of up to 25 first names from an input file nameData.txt and allows the user to display the name data, sort it in ascending or descending order, count the number of occurrences of a given name, or exit the program. The input file consists of a single names per line with each line terminated with an end of line (i.e. using Enter key to end the line). Your program should...

  • 15.1: Tallying Votes Elections are a formal group-decision making process by which a population chooses a...

    15.1: Tallying Votes Elections are a formal group-decision making process by which a population chooses a person to hold office, such as the mayor of a city. Another use of elections is to accept or reject a political proposition. Most election results are tallied, or counted, using electronic voting. Most electronic voting machines use a computer to take care of the chore of casting and counting votes. This Tuesday, November 6 (the date your assignment is due) is election day....

  • (2 bookmarks) In JAVA You have been asked to write a program that can manage candidates...

    (2 bookmarks) In JAVA You have been asked to write a program that can manage candidates for an upcoming election. This program needs to allow the user to enter candidates and then record votes as they come in and then calculate results and determine the winner. This program will have three classes: Candidate, Results and ElectionApp Candidate Class: This class records the information for each candidate that is running for office. Instance variables: first name last name office they are...

  • THIS IS FOR C++ PROGRAMMING USING VISUAL STUDIO THE PROGRAM NEEDS TO BE IN C++ PROGRAMMING #inclu...

    THIS IS FOR C++ PROGRAMMING USING VISUAL STUDIO THE PROGRAM NEEDS TO BE IN C++ PROGRAMMING #include "pch.h" #include #include using namespace std; // Function prototype void displayMessage(void); void totalFees(void); double calculateFees(int); double calculateFees(int bags) {    return bags * 30.0; } void displayMessage(void) {    cout << "This program calculates the total amount of checked bag fees." << endl; } void totalFees() {    double bags = 0;    cout << "Enter the amount of checked bags you have." << endl;    cout <<...

  • Your job is to write a program that will help us keep track of the donations to these candidates....

    Help with C++ Code (using visual studio) preferred Typed Result: Your job is to write a program that will help us keep track of the donations to these candidates. You will assume that the program is written for this election where Anders and Valerie are running. It is OK to hard code these into your program. Don't worry about case sensitivity of names Here are the features of the program Feature #1: Contribute to a Campaign [60 points] When someone...

  • I am struggling with a program in C++. it involves using a struct and a class...

    I am struggling with a program in C++. it involves using a struct and a class to create meal arrays from a user. I've written my main okay. but the functions in the class are giving me issues with constructors deconstructors. Instructions A restaurant in the Milky way galaxy called “Green Alien” has several meals available on their electronic menu. For each food item in each meal, the menu lists the calories per gram and the number of grams per...

  • Need help writing this code in python. This what I have so far. def display_menu(): print("======================================================================")...

    Need help writing this code in python. This what I have so far. def display_menu(): print("======================================================================") print(" Baseball Team Manager") print("MENU OPTIONS") print("1 - Calculate batting average") print("2 - Exit program") print("=====================================================================")    def convert_bat(): option = int(input("Menu option: ")) while option!=2: if option ==1: print("Calculate batting average...") num_at_bats = int(input("Enter official number of at bats: ")) num_hits = int(input("Enter number of hits: ")) average = num_hits/num_at_bats print("batting average: ", average) elif option !=1 and option !=2: print("Not a valid...

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