First Program Start.

I've been trying to do this program for a few hours now, I've tried googling parts, asking classmates, and trial and error, and I'm just not understanding how to do this assignment. I just need some help getting started. This is my first assignment and nothing really makes any sense to me yet in C++. I appreciate any help.


"Write a C and C++ program that assigns the largest and smallest short, int, and long, both signed and unsigned, from standard headers/libraries to variables of the correct data type.

Print the values in decimal (base 10), hexadecimal (base 16), and octal (base 8) using dec, hex, and oct with cout in C++ and %d, %x, and %o with printf() in C.
Now, print the decimal (base 10) values of adding one to each variable containing the maximum numbers and subtracting one from the variables containing the minimum
values (even zero for unsigned).
Lastly, directly compute the largest and smallest short, int, and long, both signed and unsigned, using pow(), which is in the math.h for C and cmath for C++. You only need to print the decimal values for these numbers."

This is what I have so far, I'm not sure if I'm on the right track or even close.

#include<iostream>
#include<stdio.h>
#include<math.h>
#include<cmath>
#include<climits>

#define NUM_BITS_BYTE 8


int main() {

//const int NUM_BITS_BYTE=8;

//Prints the maximum signed long that can be represented in C and C++
std::cout << "The long max in decimal is: " <<std::dec << LONG_MAX << std::endl;

std::cout << "The long max in hex is: " <<std::hex << LONG_MAX << std::endl;

std::cout << "And the long max in oct is: " <<std::oct << LONG_MAX << std::endl;

std::cout << "The unsign long max in dec is: " <<std::dec << ULONG_MAX << std::endl;

std::cout << "The unsign long max in hex is: " <<std::hex << ULONG_MAX << std::endl;

std::cout << "The unsign long max in oct is: " <<std::oct << ULONG_MAX << std::endl;

std::cout << "The unsigned short max in dec is: " <<std::dec << USHRT_MAX << std::endl;

std::cout << "The unsigned short max in hex is: " <<std::hex << USHRT_MAX << std::endl;

std::cout << "The unsigned short max in oct is: " <<std::oct << USHRT_MAX << std::endl;


return 0;
}
Last edited on
Topic archived. No new replies allowed.