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

I am trying to get started out in the right direction on this code. I have been

ID: 3637529 • Letter: I

Question

I am trying to get started out in the right direction on this code. I have been working on it for a while now and can't seem to figure things out.....
My main problem stems from inexperience, but I am working on that.
In this project I am required to write a program that requests numbers from the user and then prints each number out in a variety of formats using scanf() and printf().

For each number typed in, your program should print out two lines:

first line
integer, right justified in a 10 character field
hex representation of the integer (the 4-byte actual value that is independent of the machine’s endian-ness)

second line
floating, right justified in a 10 character field, with 2 digits to the right of the decimal point
hex representation of the floating number (the 4-byte actual value that is independent of the machine’s endian-ness)

example:

scanf and printf in c!!!!!!!!!!!!!!!!!!!

byte order: little-endian

> 2
2 0x00000002
2.00 0x40000000
> -2
-2 0xFFFFFFFE
-2.00 0xC0000000
> 0
0 0x00000000
0.00 0x00000000

My program should repeatedly ask for input until the user types in a zero, and then it should exit. Each number in the input will be an integer, expressed as a decimal number.

Any help getting started on this would be greatly appreciated. Thanks!

#######################################################################


// do not change this code except in the following ways:
// * write code for the following functions:
// * bigOrSmallEndian()
// * getNextFloat()
// * printLinesForNumber()
// * change studentName by changing "I. Forgot" to your actual name

#include <stdio.h>
#include <stdlib.h>

static char *studentName = "I. Forgot";

// report whether machine is big or small endian
void bigOrSmallEndian()
{
int num = 1;
if(*(char *)&num == 1)
{
printf("Byte Order: Little-Endian ");
}
else
{
printf("Big-Endian ");
}



}

// get next float using scanf()
// returns 1 (success) or 0 (failure)
// if call succeeded, return float value via f pointer
int getNextFloat(float *f)
{
// replace this code with the call to scanf()
*f = 0.0;
return 1; // in C, a zero value means false, anything else means true
}

// print requested data for the given number
void printNumberData(float f)
{
}

// do not change this function in any way
int main(int argc, char **argv)
{
float f; // number currently being analyzed
int nValues; // number of values successfully parsed by scanf

printf("scanf and printf in c!!!!!!!!!!!!!!!!!!!", studentName);
bigOrSmallEndian();
for (;;) {
if (argc == 1) // allow grading script to control ...
printf("> "); // ... whether prompt character is printed
nValues = getNextFloat(&f);
if (! nValues) { // encountered bad input
printf("bad input ");
while (getchar() != ' ') ; // flush bad line from input buffer
continue;
}
printNumberData(f);
if (f == 0.0)
break;
}
printf(" ");
return 0;
}

Explanation / Answer

please rate - thanks

hope this helps. your explanation has many discrepancies. example, say Each number in the input will be an integer, expressed as a decimal number.

but then the number is a float

did the best to replicate your sample as possible. Also I fixed an error in the main program, even though you said not to. see the comment



// do not change this code except in the following ways:
// * write code for the following functions:
// * bigOrSmallEndian()
// * getNextFloat()
// * printLinesForNumber()
// * change studentName by changing "I. Forgot" to your actual name

#include <stdio.h>
#include <stdlib.h>
static char *studentName = "I. Forgot";

// report whether machine is big or small endian
void bigOrSmallEndian()
{
int num = 1;
if(*(char *)&num == 1)
{
printf("Byte Order: Little-Endian ");
}
else
{
printf("Big-Endian ");
}



}

// get next float using scanf()
// returns 1 (success) or 0 (failure)
// if call succeeded, return float value via f pointer
int getNextFloat(float *f)
{
// replace this code with the call to scanf()
scanf("%f",f);
return 1; // in C, a zero value means false, anything else means true
}

// print requested data for the given number
void printNumberData(float f)
{printf("%d %0#10X ",(int)f,(int)f);
printf("%.2f %0#10X ",f,*(int *)&f);
}

// do not change this function in any way
int main(int argc, char **argv)
{
float f; // number currently being analyzed
int nValues; // number of values successfully parsed by scanf

printf("scanf and printf in c!!!!!!!!!!!!!!!!!!!%s ", studentName); //corrected it
bigOrSmallEndian();
for (;;) {
if (argc == 1) // allow grading script to control ...
printf("> "); // ... whether prompt character is printed
nValues = getNextFloat(&f);
if (! nValues) { // encountered bad input
printf("bad input ");
while (getchar() != ' ') ; // flush bad line from input buffer
continue;
}
printNumberData(f);
if (f == 0.0)
break;
}
printf(" ");
return 0;
}

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