Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello Chegg, I need a complete solution with comments, whose output looks Like t

ID: 645597 • Letter: H

Question

Hello Chegg, I need a complete solution with comments, whose output looks Like this?

Question: Create a function called numberConvert:

- A character array of up to 30 called inputData, reading/printing is NOT done in this function
- An integer called N, number of elements in the array
- A character called whatToDo

- "I" - create integer
- "D" - create double

- output Integer number called outputInteger
- output Double number called outputDouble

This function can NOT use any function given to 'C' to do this conversion from character to number.
You must create your own algorithm to do the computation.
An integer number will stop at it's first decimal point or when the array is done
A Double will stop at the end of the array
Bypass all NON-numbers, '-' and '.' is valid.
Remember to include a possible leading '-' for a negative number

The main program will read in one line at a time and load the array. FIRST CHAR is the I or D then a space then the characters to convert.
The program will stop when there is a line with NOTHING in it. (you did this in the sentence program)

Ouput will look like:

Original INPUT: whatToDo integer Double
-------------------- ----------- -------------- -----------------
XXXXXXXXXXXX X 999999 999999.999999
...

SAMPLES:

123.45 I 123 0 -78654 I -78654 0 1ABH4C-DE3 I 143 0 123.45- D 0 123.450000 -98-654.A9B9.CDE7 D 0 -98654.997000 1AB567SDFR9.A8765CD D 0 15679.876500 ab.124d7 D 0 .124700

Explanation / Answer

// Program for number convert to Integer or double
#include <stdio.h>
#include <math.h>

void numberConvert(char inputData[], int N, char whatToDo)
{
   int i,dotpos;
   int outputInteger=0;
   double outputDouble=0.0;
  
   //integer conversion
        if(whatToDo=='I')
   {
       for(i=0;inputData[i]!='' && inputData[i]!='.';i++)
           {
       if((inputData[i]>=48 && inputData[i]<=57) || (inputData[i]=='-' && i==0))
       outputInteger=outputInteger*10+inputData[i]-'0';
           }
   printf(" Converted to Integer is : %d",outputInteger);      
   }
      
   //double conversion
   if(whatToDo=='D')
   {
       for(i=0;inputData[i]!='';i++)
       {
       if((inputData[i]>=48 && inputData[i]<=57) || (inputData[i]=='-' && i==0))
       {
           if(inputData[i]=='.')
           dotpos=N-i-1;
       outputDouble=outputDouble*10+(inputData[i]-'0');
       }
       }
       outputDouble/=pow(10,dotpos);
   printf(" Converted to Double is : %lf",outputDouble);      
   }
  
}  
  
int main()
{
   char inputData1[]="673.90",inputData2[]="-78654",inputData3[]="1ABH4C-DE3";
   char inputData4[]="123.45-",inputData5[]="-98-654.A9B9.CDE7",inputData6[]="1AB567SDFR9.A8765CD",inputData7[]="ab.124d7";
   numberConvert(inputData1,06,'I');
   numberConvert(inputData2,06,'I');
   numberConvert(inputData3,10,'I');
   numberConvert(inputData4,7,'D');
   numberConvert(inputData5,17,'D');
   numberConvert(inputData6,19,'D');
   numberConvert(inputData7,8,'D');
return 0;
}

//Sample Output I will execute and send you soon

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote