This must be done in Visual Studio 2010 and only use #include stdafx.h and/or #i
ID: 3695389 • Letter: T
Question
This must be done in Visual Studio 2010 and only use #include stdafx.h and/or #include <stdio.h>
Using the program below as a guide, write a new program to:
Create variables for num1, num2 (2 integers), num3, num4 (2 doubles) and grade1, grade2 (2 characters).
Set values for each of these variables to: 50, 100, 25.50, 35.50, 'a', and 'b'.
Print the values for each of the variables to the screen.
Now create a function ChangeValues and send the addresses for the 2 integers, two doubles, and 2 characters to this function (they will be passed into pointer variables).
Have the function change the values for the variables to 10, 20, 5.50, 6.50, 'c', and 'd'.
After the function finishes and returns back to the main program, print the values again to show that the values that belonged to the main program were changed by the function.
Don't forget to add a line at the very top: #include "stdafx.h" (needed for Visual Studio software).
Explanation / Answer
#include "stdafx.h"
#include <stdio.h>
double ChangeValues( int*, int*, double*, double*, char*, char*);
int main(void)
{
int num1=50,num2=100;
double num3=25.50,num4=35.50;
char grade1='a',grade2='b';
printf("Before integers are %d,%d doubles are %.2f,%.2f chars are %c,%c",num1,num2,num3,num4,grade1,grade2);
ChangeValues(&num1, &num2, &num3, &num4, &grade1, &grade2);
return 0;
}
double ChangeValues( int *num1, int *num2, double *num3, double *num4, char *grade1, char *grade2)
{
*num1 = 10;
int a= *num1;
*num2 = 20;
int b=*num2;
*num3 = 5.50;
double c= *num3;
*num4 = 6.50;
double d = *num4;
*grade1 = 'c';
char e= *grade1;
*grade2 = 'd';
char f= *grade2;
printf(" After integers are %d,%d doubles are %.2f,%.2f chars are %c,%c",a,b,c,d,e,f);
return (a,b,c,d,e,f);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.