A total of 6 Presidents have been elected without any prior elected position in government.
Three of them had careers in the military:
Zachary Taylor who was a Major General in the US Army, and served in, and became famous in the Mexican War of 1846-1848, and was elected President in 1848.
Ulysses S. Grant, who was a General in the Civil War, gained the surrender of Confederate General Robert E. Lee to end the war, and was elected President in 1868.
Dwight D. Eisenhower, who was General of the Army during World War II, and planned the D-Day invasion on France on June 6, 1944, and was elected President in 1952.
Two other Presidents had appointed experience in the US government as Cabinet Officers before they were elected President:
William Howard Taft, who served as Secretary of War under Theodore Roosevelt, and was elected President in 1908.
Herbert Hoover, who served as Secretary of Commerce under Warren G. Harding and Calvin Coolidge, and was elected President in 1928.
And then, finally, there is Donald Trump, in a category by himself, as Chairman of the Trump Organization, his whole career in real estate, and also a reality star on television, a public figure for decades, but never holding office in any form by election or appointment, or by military service, but elected President in 2016.