Question

In: Computer Science

My program is working until it gets to val2 / 1000000. I keep getting my answer...

My program is working until it gets to val2 / 1000000. I keep getting my answer to be 0. Can someone help please?

int main()
{
   int n, num, num1, num2, time, val1, val2, Ts;
  
  
  
  
   printf("**** Welcome to the Time Study Program ****\n");
   printf("\n");

   printf("Enter the number of elements for the give operation being perform\n");
   printf("Number of elements: ");
   scanf_s("%d", &n);
   printf("\n");

   printf("Enter the Performance Rating (PR) factor as a percentage\n");
   printf("RF: ");
   scanf_s("%d", &num1);
   printf("\n");

   printf("Enter the Personal Fatigue Delay (PFD) value as a perventage\n");
   printf("PFD: ");
   scanf_s("%d", &num2);
   printf("\n");

   printf("Now enter the measured cycle times in hundredths of a minute for each element\n");
   printf("<Note: Time entered should be relative not absolute");
   printf("\n");
  
   //Allowing the user to enter a time for each element
   for (num = 1; num <= n; num++)
   {

       printf("Element\t%d: ", num);
       scanf_s("%d", &time);
       printf("\n");
   }
  
   if (time >= 0)
   {
       val1 = ((time) * (num1)); //solving for normal time
       val2 = ((val1) * (100 + num2)); //solving for standard time
       printf("The answer is: %d", val2);

      
       Ts = (val2) / (1000000); //converting answer to hundreths of a minute
       printf("The answer is: %d", Ts);
      
       printf("**** Time Study Results ****\n");
       printf("The Time Standard is: TS = %d minutes", Ts);

   }
  
  
   return 0;
}

Solutions

Expert Solution

When you divide to integers you answer will be displayed with out decimals numbers to get the decimal values we have to use the variables as float or double so that we can get the decimal values when we devide

%f is used to print the floating point numbers on the screen

Code:

#include<stdio.h>
int main()
{
int n, num, num1, num2, time, val1;
float Ts,val2;
/*Just place Ts and val2 as floating point numbers*/
printf("**** Welcome to the Time Study Program ****\n");
printf("\n");
printf("Enter the number of elements for the give operation being perform\n");
printf("Number of elements: ");
scanf_s("%d", &n);
printf("\n");
printf("Enter the Performance Rating (PR) factor as a percentage\n");
printf("RF: ");
scanf_s("%d", &num1);
printf("\n");
printf("Enter the Personal Fatigue Delay (PFD) value as a perventage\n");
printf("PFD: ");
scanf_s("%d", &num2);
printf("\n");
printf("Now enter the measured cycle times in hundredths of a minute for each element\n");
printf("<Note: Time entered should be relative not absolute");
printf("\n");
//Allowing the user to enter a time for each element
for (num = 1; num <= n; num++)
{
printf("Element\t%d: ", num);
scanf_s("%d", &time);
printf("\n");
}
if (time >= 0)
{
val1 = ((time) * (num1)); //solving for normal time
val2 = ((val1) * (100 + num2)); //solving for standard time
printf("The answer is: %f\n", val2);
   /*insted of %d place %f as it is a floating point number */
Ts = (val2) / (1000000); //converting answer to hundreths of a minute
printf("The answer is: %f\n", Ts);
/*insted of %d place %f as it is a floating point number */
printf("**** Time Study Results ****\n");
printf("The Time Standard is: TS = %f minutes", Ts);
   /*insted of %d place %f as it is a floating point number */
}
return 0;
}

Output:

Indentation:


Related Solutions

I working on this program in C++ and I keep getting 20 errors of the same...
I working on this program in C++ and I keep getting 20 errors of the same type again.cpp:36:11: error: use of undeclared identifier 'Polynomial' int main() { // create a list of polinomials vector<Polynomial> polynomials; // welcome message cout << "Welcome to Polynomial Calculator" << endl; int option = 0; while (option != 6) { // display menu displayMenu(); // get user input; cin >> option; if (option == 1) { cout << "Enter a polynomial :" << endl; string...
My code works in eclipse, but not in Zybooks. I keep getting this error. Exception in...
My code works in eclipse, but not in Zybooks. I keep getting this error. Exception in thread "main" java.util.NoSuchElementException at java.base/java.util.Scanner.throwFor(Scanner.java:937) at java.base/java.util.Scanner.next(Scanner.java:1478) at Main.main(Main.java:34) Your output Welcome to the food festival! Would you like to place an order? Expected output This test case should produce no output in java import java.util.Scanner; public class Main {    public static void display(String menu[])    {        for(int i=0; i<menu.length; i++)        {            System.out.println (i + " - " + menu[i]);...
I do not know why I keep getting this question wrong, I triple checked my work!...
I do not know why I keep getting this question wrong, I triple checked my work! A distribution of values is normal with a mean of 80 and a standard deviation of 18. From this distribution, you are drawing samples of size 23. Find the interval containing the middle-most 40% of sample means: ANSWER HERE Enter your answer using interval notation. In this context, either inclusive or exclusive intervals would be acceptable. Your numbers should be accurate to 1 decimal...
HI. I have been trying to run my code but I keep getting the following error....
HI. I have been trying to run my code but I keep getting the following error. I can't figure out what I'm doing wrong. I also tried to use else if to run the area of the other shapes but it gave me an error and I created the private method. Exception in thread "main" java.util.InputMismatchException at java.base/java.util.Scanner.throwFor(Scanner.java:939) at java.base/java.util.Scanner.next(Scanner.java:1594) at java.base/java.util.Scanner.nextInt(Scanner.java:2258) at java.base/java.util.Scanner.nextInt(Scanner.java:2212) at project2.areacalculation.main(areacalculation.java:26) My code is below package project2; import java.util.Scanner; public class areacalculation { private static...
A flycatcher is trying to catch passing bugs and will keep going until it gets one,...
A flycatcher is trying to catch passing bugs and will keep going until it gets one, or until it has tried five times, whichever comes first. The probability that it catches a bug on any given try is 20%, and each try is independent. a) What is the probability that it catches its first bug on an even-numbered attempt? b) What is the probability that it catches its first bug on an odd-numbered attempt? c) What is the probability that...
I did most of this problem theres only a part that I keep getting wrong or...
I did most of this problem theres only a part that I keep getting wrong or not getting. I need help figuring out the blank boxes. that says Purchasing and Power and Question 2. Rest is done Sequential Method Jasmine Company manufactures both pesticide and liquid fertilizer, with each product manufactured in separate departments. Three support departments support the production departments: Power, General Factory, and Purchasing. Budgeted data on the five departments are as follows: Support Departments Producing Departments Power...
Syntax error in C. I am not familiar with C at all and I keep getting...
Syntax error in C. I am not familiar with C at all and I keep getting this one error "c error expected identifier or '(' before } token" Please show me where I made the error. The error is said to be on the very last line, so the very last bracket #include #include #include #include   int main(int argc, char*_argv[]) {     int input;     if (argc < 2)     {         input = promptUserInput();     }     else     {         input = (int)strtol(_argv[1],NULL, 10);     }     printResult(input);...
I have a problem with getting my message clearly across. While giving my speech I like...
I have a problem with getting my message clearly across. While giving my speech I like to scan the room to read the audience. I zero in on the people who seem uninterested in what I have to say and start to panic. Instead of focusing on giving my speech my brain starts going over every possible reason they might not be interested. Did I offend them? Am I not using the right words? I never stop to consider maybe...
I keep getting an error that I cannot figure out with the below VS2019 windows forms...
I keep getting an error that I cannot figure out with the below VS2019 windows forms .net framework windows forms error CS0029 C# Cannot implicitly convert type 'bool' to 'string' It appears to be this that is causing the issue string id; while (id = sr.ReadLine() != null) using System; using System.Collections.Generic; using System.IO; using System.Windows.Forms; namespace Dropbox13 { public partial class SearchForm : Form { private List allStudent = new List(); public SearchForm() { InitializeComponent(); } private void SearchForm_Load(object...
I am making a html game with phaser 3 I keep getting an error at line...
I am making a html game with phaser 3 I keep getting an error at line 53 of this code (expected ;) I have marked the line that needs to be fixed. whenever I add ; my whole code crashes const { Phaser } = require("./phaser.min"); var game; var gameOptions = {     tileSize: 200,     tileSpacing: 20,     boardSize: {     rows: 4,     cols: 4     }    }    window.onload = function() {     var gameConfig = {         width: gameOptions.boardSize.cols * (gameOptions.tileSize +             gameOptions.tileSpacing) + gameOptions.tileSpacing,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT