So I am trying to display numbers in different formats


Here is some things I need for the program to do and this is in C by the way



first line: integer, right justified in a 10 character field hex representation of that integer
second line: floating point, right justified in a 10 character field, with 2 digits to the right of the decimal point hex representation of that floating number

well my program crashes when I run it like when the program prompts to enter a number and I press enter it crashes so what am I doing wrong?


so I keep getting an output of 2685984 as my output but its shooting that number out regardless of what number I do put. I can put any number in there and it still displays the same number.. what am I doing wrong? maybe I just gotta step away from programming and get back to this tommorrow.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

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





int main() {

unsigned int number[200];
    
printf("Please enter one value for each type of the following,char,int,");
printf("char, float\n");
printf("\n");
printf("Please enter your int  value now\n");

scanf("%u",number);

printf("Your int value is:%u\n",number);
printf("\n");
printf("Please enter integer value\n");


    
system("pause");

    return 0;
}
 
Last edited on
Line 12 declares an array. You only need to scanf() one integer.

12
13
unsigned int number;
19
20
scanf("%d",&number);

If you must work on an array, then you must printf() the integer only and not the array address:

21
22
printf("Your int value is:%d\n",number[0]);
printf("\n");

Also, http://www.cplusplus.com/articles/iw6AC542/ because http://www.cplusplus.com/articles/j3wTURfi/

Hope this helps.
does %d print out hex format? I should get some sort of out put of like 0x and a bunch of random numbers but I am not getting that..
Er, so far you have only posted problems getting numbers, and you have only used decimal format specifiers. I assumed you have gotten far enough along the documentation to do what you have hitherto done.

Print format specifiers for hex and oct, as well as floating-point options, are all listed here
http://www.cplusplus.com/reference/clibrary/cstdio/printf/

Good luck!
Topic archived. No new replies allowed.