
Help with c homework please
http://www.cs.ucf.edu/courses/cop3223/spr2021/section2/cop3223sp21ass1.pdf
I need help with coding Problem A, B, and C
B and C are if-then-else statements/constructs
1 Expert Answer

Patrick B. answered 01/30/21
Math and computer tutor/teacher
#include <stdio.h>
#define TAX_RATE (0.065)
int main()
{
float price;
printf(" What is the cost of the item to be purchased (in dollars )??? :> ");
scanf("%f",&price);
int n;
printf(" How many of the item are you purchasing ? :>");
scanf("%d",&n);
int tax_flag;
printf(" Is the item a taxed item (1 = yes 0 = no) ? :>");
scanf("%d",&tax_flag);
double total_cost = price*n *(1+tax_flag*TAX_RATE);
printf(" The total purchase will cost $ %6.2lf \n",total_cost);
}
/**************************************************************************/
#include <stdio.h>
#define WALK_CAL (5)
#define STAND_CAL (2)
#define DRINK_CAL (20)
#define FOOD_CAL (40)
#define CALS_PER_POUND (3500)
int main()
{
int min_walking=-1;
int min_standing=-1;
int min_drinking=-1;
int min_eating=-1;
while ((min_walking<0) || (min_walking>720))
{
printf(" How many minutes were you walking ? :>");
scanf("%d",&min_walking);
}
while ((min_standing<0) || (min_standing>720))
{
printf(" How many minutes were you standing ? :>");
scanf("%d",&min_standing);
}
while ((min_drinking<0) || (min_drinking>720))
{
printf(" How many minutes were you drinking ? :>");
scanf("%d",&min_drinking);
}
while ((min_eating<0) || (min_eating>720))
{
printf(" How many minutes were you eating ? :>");
scanf("%d",&min_eating);
}
double calories = min_eating * FOOD_CAL + min_drinking * DRINK_CAL - min_walking*WALK_CAL - min_standing*STAND_CAL;
double weight = calories / CALS_PER_POUND;
printf(" You lost %6.3lf pounds today ! \n",-weight);
}
/**************************************************************************************/
#include <stdio.h>
#define FIRST_CAR_LENGTH (10)
#define NORMAL_CAR_LENGTH (8)
#define CAR_CAPACITY (4)
int main()
{
int iLoop;
int n=-1;
int legal_distance;
int num_trains;
int num_cars;
int excess_length;
int num_people;
while (n<0)
{
printf(" Please input N :>");
scanf("%d",&n);
}
for (iLoop=0; iLoop<n; iLoop++)
{
int maxTrackLength=-1;
int maxTrainLength=-1;
while ((maxTrackLength<0) || (maxTrackLength>10000))
{
printf(" What is the total length of the track in feet ? :>");
scanf("%d",&maxTrackLength);
}
while ((maxTrainLength<10) || (maxTrainLength>100))
{
printf(" What is the max length of the train in feet ? :>");
scanf("%d",&maxTrainLength);
}
legal_distance = maxTrackLength/4;
num_trains = legal_distance/maxTrainLength;
num_cars = (maxTrainLength - FIRST_CAR_LENGTH)/NORMAL_CAR_LENGTH +1;
num_people = num_cars * CAR_CAPACITY * num_trains;
excess_length = (maxTrainLength - FIRST_CAR_LENGTH)%NORMAL_CAR_LENGTH;
printf(" Your ride can have at most %d people on it at a time. \n",num_people);
if (excess_length>0)
{
printf(" Maximum train length has a surplus of %d feet \n ",excess_length);
}
else
{
printf(" Maximum train length fits exactly \n");
}
} //for loop
}
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Patrick B.
GO KNIGHTS!!!!01/30/21