Question

In: Computer Science

i keep getting return value ignored and and conversion from double to float , possible data...

i keep getting return value ignored and and conversion from double to float , possible data loss dont know how to fix the mistakes. if you could please fix it.

#define _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_DEPRECATE
#define _CRT_NONSTDC_NO_DEPRECATE
#include
#include


void O_Read_age_1()
{
   int sum = 0;
   int i;
   for (i = 1; i <= 2; i++)
   {

       int temp;
       printf("please enter the age of employee %d:", i);
       scanf("%d", &temp);
       sum += temp;
   }

   printf("\n");
   printf("The total age of all employees is%d\n", sum);
   return;
}
float O_Read_Salary_1()
{

   float sum = 0;
   int i;
   for (i = 1; i <= 2; i++)
   {
       printf("PLease enter the salary of the employee %d:", i);
       float temp;
       scanf("%f", &temp);
       for (; ((temp < 1000)) || ((temp > 6000));)
       {
           printf("Salary should be from 1000 to 6000:");
           scanf("%f", &temp);
       }
       if (temp <= 2150)
       {
           float inc = temp * 0.2;
           sum += temp;
           sum += inc;
       }
       else if ((temp > 2150) && (temp <= 4150))
       {

           float inc = temp * 0.15;
           sum += temp;
           sum += inc;
       }
       else if ((temp > 4150) && (temp <= 5150))
       {
           float inc = temp * 0.1;
           sum += temp;
           sum += inc;
       }
   }
   return sum;
}
void O_Read_Gender_1()
{
   int males = 0;
   int females = 0;
   int j = 0;
   char ch;
   for (j = 0; j < 2; j++)
   {
       printf("Enter the gender of employee %d (F or M):", j + 1);
       ch = getchar();
       scanf("%s",&ch);
       printf("\n");
       if (ch == 'F')
       {
           females++;
       }
       else if (ch == 'M')
       {
           males++;
       }
   }
   printf("The number of female employees is %d \n", females);
   printf("The number of male employees is %d \n", males);
  
   return;
}
void O_Calculate_Bonus_1()
{
   int bonus = 0;
   printf("Enter the rank of the company: %d");
   printf("\n");
   int Rank;
   scanf("%d", &Rank);
   printf("Enterr the ID of the company: ");
   int id;
   scanf("%d", &id);
   printf("\n");
   if (Rank == 1)
   {
       bonus = 15;
   }
   if (Rank == 2)
   {
       bonus = 10;
   }
   else
   {
       bonus = 5;
   }
   printf("Company ID = %d\n", id);
   printf("Rank= %d\n", Rank);
   printf("Bonus = %d", bonus);
   printf("Student: Bader Alostad Section:O1 ID:45191 - Semester Spring 2 online Press any button to continue...\n");
   return;
}


int main()
{
   float ans = O_Read_Salary_1();
   printf("\n");
   printf("The Function Read_Salary return the value %f \n", ans);
   O_Read_age_1();
   O_Read_Gender_1();
   O_Calculate_Bonus_1();
   return 0;

}

Solutions

Expert Solution

float inc = temp * 0.2;

float inc = temp * 0.15;

float inc = temp * 0.1;

inc is float

0.2 , 0.15 and 0.1 are double So changed to

float inc = temp * 0.2f;

float inc = temp * 0.15f;  

float inc = temp * 0.1f;

to tell the compiler that it's a float, not a double.

==========================================

After fix the program :

#define _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_DEPRECATE
#define _CRT_NONSTDC_NO_DEPRECATE
#include<stdio.h>
#include<stdlib.h>


void O_Read_age_1()
{
   int sum = 0;
   int i;
   for (i = 1; i <= 2; i++)
   {

       int temp;
       printf("please enter the age of employee %d:", i);
       scanf("%d", &temp);
       sum += temp;
   }

   printf("\n");
   printf("The total age of all employees is%d\n", sum);
   return;
}
float O_Read_Salary_1()
{

   float sum = 0;
   int i;
   for (i = 1; i <= 2; i++)
   {
       printf("PLease enter the salary of the employee %d:", i);
       float temp;
       scanf("%f", &temp);
       for (; ((temp < 1000)) || ((temp > 6000));)
       {
           printf("Salary should be from 1000 to 6000:");
           scanf("%f", &temp);
       }
       if (temp <= 2150)
       {
           float inc = temp * 0.2f;
           sum += temp;
           sum += inc;
       }
       else if ((temp > 2150) && (temp <= 4150))
       {

           float inc = temp * 0.15f;
           sum += temp;
           sum += inc;
       }
       else if ((temp > 4150) && (temp <= 5150))
       {
           float inc = temp * 0.1f;
           sum += temp;
           sum += inc;
       }
   }
   return sum;
}
void O_Read_Gender_1()
{
   int males = 0;
   int females = 0;
   int j = 0;
   char ch;
   for (j = 0; j < 2; j++)
   {
       printf("Enter the gender of employee %d (F or M):", j + 1);
       ch = getchar();
       scanf("%s",&ch);
       printf("\n");
       if (ch == 'F')
       {
           females++;
       }
       else if (ch == 'M')
       {
           males++;
       }
   }
   printf("The number of female employees is %d \n", females);
   printf("The number of male employees is %d \n", males);

   return;
}
void O_Calculate_Bonus_1()
{
   int bonus = 0;
   printf("Enter the rank of the company: ");
   printf("\n");
   int Rank;
   scanf("%d", &Rank);
   printf("Enterr the ID of the company: ");
   int id;
   scanf("%d", &id);
   printf("\n");
   if (Rank == 1)
   {
       bonus = 15;
   }
   if (Rank == 2)
   {
       bonus = 10;
   }
   else
   {
       bonus = 5;
   }
   printf("Company ID = %d\n", id);
   printf("Rank= %d\n", Rank);
   printf("Bonus = %d", bonus);
   printf("Student: Bader Alostad Section:O1 ID:45191 - Semester Spring 2 online Press any button to continue...\n");
   return;
}


int main()
{
   float ans = O_Read_Salary_1();
   printf("\n");
   printf("The Function Read_Salary return the value %f \n", ans);
   O_Read_age_1();
   O_Read_Gender_1();
   O_Calculate_Bonus_1();
   return 0;

}

NOTE: If you getting any problem , please let me know through comments; I will surely revert back to you.

Please give a up vote .....
Thank you.......


Related Solutions

Decimal value data types such as float and double represent the decimal number as an approximation....
Decimal value data types such as float and double represent the decimal number as an approximation. In other words, float or double arithmetic do not give exact answer but near approximation to the answer. As an example, run the following program and check its result: #include <iostream> using namespace std; int main() { float x= 0.1 * 7; if (x == 0.7) cout<< "TRUE. \n"; else cout<< "FALSE. \n"; return 0; } In some situations, we need our programs to...
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...
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 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,...
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...
In java, I keep getting the error below and I can't figure out what i'm doing...
In java, I keep getting the error below and I can't figure out what i'm doing wrong. Any help would be appreciated. 207: error: not a statement allocationMatrix[i][j];
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT