Question

Read the file and make a vector with the total for each Gender/Alchohol frequency. C++

Ask the user for an age range (min and max) Searc

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

#include <stdio.h>
#include <string.h>

int main(void) {
int age;
char gender[10];
   int weight;
   int beers;
   int shots;
   int hours;
double a;
  
printf("Should I Drive?\n");
   printf("What is your age?\n");
   scanf("%d", &age);
   if (age < 21)
   {
       printf("No, you shouldn't drive.");
   }
   else
   {
       printf("Okay. Are you male or female?\n");
       scanf("%s", &gender);
if (strcmp(gender, "male") == 0)
{
a = 0.73;
}
if (strcmp(gender, "female") == 0)
{
a = 0.66;
}
       printf("So you are a %s. And how much do you weigh?\n", gender);
       scanf("%d", &weight);
       printf("That's enough with the personal questions. How many beers (12 oz.) have you had to drink?\n");
       scanf("%d", &beers);
       printf("And how many shots (1.25 oz.)?\n");
       scanf("%d", &shots);
  
double content = ((beers * (12 * .05)) + (shots * (1.25 * .4)));
       printf("You have had %.2lf oz. of alcohol tonight.\n", content);
       printf("How many hours (round down) has it been since you started drinking?\n");
       scanf("%d", &hours);
  
double bac = (content * 5.14 / (weight * a)) - (0.015 * hours);

if (bac <= 0.08)
{
double amtunder = 0.08 - bac;
printf("Your BAC is %.3lf under the legal limit. You are legally able to drive.", amtunder);
}
if (bac > 0.08)
{
double amtover = bac - 0.08;
printf("Your BAC is %.3lf over the legal limit. You are not legally able to drive.", amtover);
}
   }
   return 0;
}

Add a comment
Know the answer?
Add Answer to:
Read the file and make a vector with the total for each Gender/Alchohol frequency. C++ Ask...
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
  • //Done in C please! //Any help appreciated! Write two programs to write and read from file...

    //Done in C please! //Any help appreciated! Write two programs to write and read from file the age and first and last names of people. The programs should work as follows: 1. The first program reads strings containing first and last names and saves them in a text file (this should be done with the fprintf function). The program should take the name of the file as a command line argument. The loop ends when the user enters 0, the...

  • /* Graph read from file, and represnted as adjacency list. To implement DFS and BFS on...

    /* Graph read from file, and represnted as adjacency list. To implement DFS and BFS on the graph */ #include <iostream> #include <sstream> #include <fstream> #include <vector> #include <utility> #include <unordered_map> #include <set> #include <queue> using namespace std; // Each vertex has an integer id. typedef vector<vector<pair<int,int>>> adjlist; // Pair: (head vertex, edge weight) adjlist makeGraph(ifstream& ifs); void printGraph(const adjlist& alist); vector<int> BFS(const adjlist& alist, int source); // Return vertices in BFS order vector<int> DFS(const adjlist& alist, int source); //...

  • Write a program in C that takes a file name as the only argument on the...

    Write a program in C that takes a file name as the only argument on the command line, and prints out the number of 0-bits and 1-bits in the file int main ( int argc , char * argv [] ) { // Check if the user gave an argument , otherwise print " ERROR : no argument " // Check if the file can be read , otherwise print " ERROR : can ’t read " // Otherwise ,...

  • Instructions C++ programming Your task is to write a class called Data, stored in a file...

    Instructions C++ programming Your task is to write a class called Data, stored in a file named Data.h. Your class should be able to store a collection (vector) of integers. In addition to the appropriate constructors, your class should also have the following methods. void add (int number); Adds a number to the data set. void print (); Prints out the entire data set on a single line, separated by space. void sort (); Sorts the data set in ascending...

  • C++ C. In the file c_final_practice.cpp: (1) Write a function void replace(vector<int>& v, int old, int...

    C++ C. In the file c_final_practice.cpp: (1) Write a function void replace(vector<int>& v, int old, int new) that replaces all occurrences of the integer old in v with the integer new. For example, if v is the vector {1,2,1,3}, then after calling replace(v, 1, 3) v should be {3,2,3,3}. (2) Write the main-function so that it prompts the user for a list of integers, and then uses your replace function to display the following lists: • The user's list with...

  • *********C Language******* Write a file final_main.c 4. Inside main(void): Write a loop that oops until the...

    *********C Language******* Write a file final_main.c 4. Inside main(void): Write a loop that oops until the entered number is 0 or negative 5. Ask the user to enter a positive int between 0 and 10 inclusive 6. If the number is < 1, it terminates. 7. Else: call the above four functions 8. Print the result of each function after its call. Q2. Write a program that removes the punctuations letters from a file and display the output to the...

  • CSC110 Lab 6 (ALL CODING IN JAVA) Problem: A text file contains a paragraph. You are to read the contents of the file, store the UNIQUEwords and count the occurrences of each unique word. When the fil...

    CSC110 Lab 6 (ALL CODING IN JAVA) Problem: A text file contains a paragraph. You are to read the contents of the file, store the UNIQUEwords and count the occurrences of each unique word. When the file is completely read, write the words and the number of occurrences to a text file. The output should be the words in ALPHABETICAL order along with the number of times they occur and the number of syllables. Then write the following statistics to...

  • Underage drinking. make a short as possible for both wild and do wild in c++ Please...

    Underage drinking. make a short as possible for both wild and do wild in c++ Please write a program that asks the user to input his/her age. If age is under 21, he/she is not allowed to drink. Printout a statement saying, "You can't drink you're under 21". If he/she is 21 or older, printout a statement saying, "Welcome to our bar". However, the bar has a capacity of only 3 people. After letting 3 people above 21 into the...

  • IN PYTHON ONLY I am looking for 4 columns, Age, Gender, Ideal Age of a Spouse,...

    IN PYTHON ONLY I am looking for 4 columns, Age, Gender, Ideal Age of a Spouse, and the message. I will have 6 rows in the table, and 4 columns, followed by  averages. Calculate the ideal age of a spouse. Enter either m or f from the keyboard in lower case. You may use string data for the gender. Convert the gender to upper case Enter an age from the keyboard, probably an integer You will need prompts telling the user...

  • Need help in C (a) Write a C program to read in a line of text...

    Need help in C (a) Write a C program to read in a line of text and count the occurrence of each English alphabet. The lowercase version of a letter is considered the same as the uppercase. To make viewing easy, the frequencies should be presented using a bar chart as follows. You can assume that the input contains only spaces, lowercase letters, uppercase letters and the newline character (i.e. the Enter key). Enter a line of text: Letter ZZz...

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