Question

USING C LANGUAGEWrite a program that computes the total weight of a cargo. Ask the user to enter multiple inputs. For each input, the user in

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

#include <stdio.h>

int main()
{
int weight,quantity,sum =0,i=1;
  
//loop for entering multiple inputs
while(i>0)
{   
  
  
printf("Input #%d.Weight of the box (lbs):",i);
  
//To take weight of the box
scanf("%d",&weight);
  
if(weight <0)
break;
  
//To take quantity of the boxes
printf("Enter quantity:");
scanf("%d",&quantity);
  
//calculating total weight of the boxes
sum = sum+(quantity * weight);
i++;
}
printf("The total weight is %d lbs.",sum);
  
return 0;
  
}

main.c #include <s tdio.h> 1 2 3 int main () 4 int weight, quantity,sum -0,i-1; 6 7 //Loop for entering multiple inputs while

Add a comment
Know the answer?
Add Answer to:
USING C LANGUAGE Write a program that computes the total weight of a cargo. Ask the...
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
  • C++ Assignment Write a program that calculates the total weight of one vehidle and one cargo...

    C++ Assignment Write a program that calculates the total weight of one vehidle and one cargo vehicle. For both vehicles, the user will give the base weight of the vehicle, the passenger capacity of the vehicle, and ONLY FOR the cargo vehicle, the cargo weight capacity all as integers. Then, the user will give passenger information for BOTH vehicles as first the number of passengers and weights of each passenger (e.g., 2 60 80 means two passengers of weight 60...

  • c++ no pointers just follow instructions Write a program (array.cpp) that read positive floating point numbers...

    c++ no pointers just follow instructions Write a program (array.cpp) that read positive floating point numbers into an array of capacity 100. The program will then ask for one of three letters(A, M or S). if the user inputs something other than one of these letters, then the program should ask for that input until an A, M, or S is entered. A do-while loop should be used for this. If the user inputs an A, then the program should...

  • Write a program that computes the average of a set of grades. The user is prompted...

    Write a program that computes the average of a set of grades. The user is prompted the following: 1-Number of grades to be entered. 2-The value of the minimum grade. 3-The value of the maximum grade. Make sure to write input validation for the following: 1-The number of grades cannot be negative! In case it is 0, it means that user has no grades to enter. 2-Each entered grade should be a valid grade between the minimum and maximum values...

  • In C using (printf and scanf) Write a program to ask the user for the weight...

    In C using (printf and scanf) Write a program to ask the user for the weight of a package, and display the shipping charges for the package. If the weight of the package is less than or equal to 0 pounds, inform the user and exit the program. The shipping charges are: Weight of Package Shipping Charge 2 pounds or less $1.25 Over 2 pounds but not more than 6 pounds $2.50 Over 6 pounds but not more than 10...

  • Write a program that reads a sequence of integers into an array and that computes the...

    Write a program that reads a sequence of integers into an array and that computes the alternating sum of all elements in the array. For example, if the program is executed with the input data: 2 1 4 9 16 9 7 4 9 11 Then it computes 2 - 1 + 4 - 9 + 16 - 9 + 7 - 4 + 9 – 11 = 4 Use a scanner object to gather the inputs from the user....

  • read instructions carefully please matlab only Write a MATLAB function for a BMI calculator that receives the inputs for body weight (lbs)and height (ft) from the user's program, calculates th...

    read instructions carefully please matlab only Write a MATLAB function for a BMI calculator that receives the inputs for body weight (lbs)and height (ft) from the user's program, calculates the BMI using the equation below, displays the BMI category, and outputs the BMI value tothe user's program W (kg) h2 (m2) BMI Display Normal if 18.5 s BMI 25 Display Overweight if 25 s BMI <30 Display Obese if BMI 2 30 Else display underweight So you will create two...

  • Write a program which: - prompts the user for 2 numerical inputs - stores their two...

    Write a program which: - prompts the user for 2 numerical inputs - stores their two inputs in variables as floats - Use a while in loop to ask a user for a valid operation: (if the user's input operation isn't one of those listed above, instead print a message telling them so, and continue asking for the valid operation) - prompts the user for an arithmetic operation ( + - * / %) - stores the user's input as...

  • Write a C program named space_to_line.c that features a while loop that continuously reads input from...

    Write a C program named space_to_line.c that features a while loop that continuously reads input from the user one character at a time and then prints that character out. The exception is that if the user inputs a space character (‘ ‘), then a newline character (‘\n’) should be printed instead. This will format the output such that every word the user inputs is on its own line. Other than changing the spaces to newlines, the output should exactly match...

  • java; programing language Write a program to calculate the price of a purchase. It should ask...

    java; programing language Write a program to calculate the price of a purchase. It should ask the user to enter the name of the item bought (like sweater, apple, …), number of items bought (4, 5 lbs,…), price per item ($40.50, $1.99 per pound,…), and the sales tax rate (8.35% for example). It should calculate the subtotal (price*number of items), sales tax (subtotal*sales tax), and total price (subtotal+ sales tax). It should print all the information in a receipt form

  • Using C++ please create a program for a first grader to practice subtractions. The program randomly...

    Using C++ please create a program for a first grader to practice subtractions. The program randomly generates two single-digit integers number1 and number2. Ask the user to input the difference of the two numbers with always the greater number as the first operand. If the user inputs wrong answer, print a message, “Your answer is wrong. The correct answer is ” with the correct answer. Otherwise print “Your answer is correct.” Hint: 1. Check if number1 < number2, otherwise swap...

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