Question: Write a simple C/C++ Win32 console application that will calculate and print out the Voltage using Ohms Law with user entered values for Current and
Write a simple C/C++ Win32 console application that will calculate and print out the Voltage using Ohms Law with user entered values for Current and Resistance. The program upon execution will request for the Current and Resistance then print out the Voltage. All values should be integers requiring resistance in Ohms, current in Amps, and voltage in Volts.
The scanf_s() function reads data from the standard input stream stdin (this will be the keyboard) and writes the data into the location given by argument (this will be the variable(s)). For scanf_s() each argument must be a pointer to the variable (so we need to add & in front of the variable name) of the type that corresponds to a type specified in format (so each type(s) from format to argument must match). Printf() is similar to scanf_s() except it prints to stdout (the screen) and doesnt require the variable to be a pointer. (& is not required in front of variable)
int scanf_s( const char *format [, argument]...); int printf( const char *format [, argument]...);
Examples of each: printf(Enter a value ); // no arguments just format // will print Enter a value char character=A; printf(The character is %c , character); // format of %c matches variable type of character // will print The character is A char character; scanf_s(%c,&character); // format of %c matches the pointed to variable type character // character will equal entered value char string1[10]; scanf_s(%s,string1,sizeof(string1)); // format of %s matches the char array which is a string (char // array), the size of the array (sizeof(string1)) must follow // pointer. The pointer to the string is actually &string1[0] // but its name without indexing provides the pointer. // string1 will equal characters entered up to size
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
