Block of Code

Practical Examples for Programmers

  • Home
  • C++
  • Java
  • Visual Basic
  • Discrete Math
  • Ask a Question

Ton of Rice

One metric ton is approximately 2205 pounds. Write a program that prompts the user to input the amount of rice, in pounds, in a bag. The program outputs the number of bags needed to store one metric ton of rice.

Write the Code:

/*
Project: Ton of Rice
Description: User inputs how many pounds of rice are in a bag.
Program calculates the number of bags needed for 1 ton of rice.
*/

#include <iostream>
using namespace std;

int main()

{
   float pounds = 0;
   float bagsInTon = 0;
   cout << "Please enter the number of pounds in each rice bag:";
   cin >> pounds;
   bagsInTon = 2205 / pounds;
   cout << "\nYou need " << bagsInTon << " bags for each ton of rice.";
   return 0;
}

Secondary Sidebar

This is the secondary sidebar

Copyright © 2025 · Metro Pro Theme on Genesis Framework · WordPress · Log in