Question

I am trying to create a function that increments x 4 times, then my program prints...

I am trying to create a function that increments x 4 times, then my program prints the results. For some reason my function is not changing the value of x. It just stays the same.

#include <stdio.h>

int Incrementx4Times(int x) // This function increments user inputted value
{
int count;  
//increments 4 different ways  
x++;
x=x + 1;
++x;
x += 1;
return x;
}

void main(void)
{
int x;
printf("x? "); scanf("%d", &x);
printf("x = %d\n", x);
Incrementx4Times(x); //Call funtion
printf("The final answer is %i", x);
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <stdio.h>

int Incrementx4Times(int x) // This function increments user inputted value
{
    int count;
//increments 4 different ways  
    x++;
    x = x + 1;
    ++x;
    x += 1;
    return x;
}

void main(void) {
    int x;
    printf("x? ");
    scanf("%d", &x);
    printf("x = %d
", x);
    x = Incrementx4Times(x); //Call funtion
    printf("The final answer is %i", x);
}

Add a comment
Know the answer?
Add Answer to:
I am trying to create a function that increments x 4 times, then my program prints...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I am trying to change my code so i no longer need the function that reads...

    I am trying to change my code so i no longer need the function that reads in the users base and height input but rather uses the implementation of argument vector in C. I want to accept command line arguments and have it calculate my area. so i want to type this into the command line and have it calculate my area project1 5 4 #include <stdio.h> void userDimensions(float *base, float *height) { scanf("%f", base); scanf("%f", height); } float calcArea(float...

  • I need the programming to be in language C. I am using a program called Zybook...

    I need the programming to be in language C. I am using a program called Zybook Prompt: Write a statement that outputs variable numObjects. End with a newline. Given: #include <stdio.h> int main(void) { int numObjects; scanf("%d", &numObjects); return 0; } What I did so far. I am not sure if its right tho? #include <stdio.h> int main(void) { int numObjects; scanf("%d", &numObjects); printf(" num Objects is "); printf("%d\n", userAge); return 0; }

  • I am trying to write a short program in C that prints the letters that are...

    I am trying to write a short program in C that prints the letters that are the same in two different arrays. I am getting a error. #include <stdio.h> int main() {           char first[7]={'y','a','s','m','i','n','e'};        char last[5]={'s','m','i','t','h'};        int i;                        while(first[i] != '\0') && (last[i] != '\0')        {            if(first[i]==last[i])                 printf("%s", first[i]);                  }         return 0;          }

  • I am trying to add a string command to my code. what am i doing wrong?...

    I am trying to add a string command to my code. what am i doing wrong? #define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include <stdio.h> #include <string.h> #include <math.h> int main(void) {    int i, j;    int rowA, colA, rowB, colB;    int A[10][10], B[10][10];    int sum[10][10];    char str1[10];    printf("This is a matrix calculator\n");    //read in size from user MATRIX A    printf("Enter in matrix A....\n");    printf("\t#row = ");    scanf("%d", &rowA);    printf("\t#col = ");   ...

  • Write a C Program that inputs an array of integers from the user along-with the length...

    Write a C Program that inputs an array of integers from the user along-with the length of array. The program then prints out the array of integers in reverse. (You do not need to change (re-assign) the elements in the array, only print the array in reverse.) The program uses a function call with array passed as call by reference. Part of the Program has been given here. You need to complete the Program by writing the function. #include<stdio.h> void...

  • I am trying to write C programming code and output will be as below but I...

    I am trying to write C programming code and output will be as below but I donno how to get the result analysis part. help me to add the 2nd part with my code: here is my code below: #include <stdio.h> #define MAX 100 struct studentMarkVariable{ int id; float marks; }; void getData(struct studentMarkVariable arrs[]); void show(struct studentMarkVariable arrs[]); int main() { printf ("####### Marks Analyzer V3.0 ####### \n");       struct studentMarkVariable arrs[MAX];     getData(arrs);     show(arrs); return 0; }...

  • I am trying to figure out why my C code is outputting "exited, segmentation fault". The...

    I am trying to figure out why my C code is outputting "exited, segmentation fault". The game is supposed to generate 4 random numbers and store them in the "secret" array. Then the user is suppose to guess the secret code. The program also calculates the score of the user's guess. For now, I printed out the random secret code that has been generated, but when the game continues, it will output "exited, segmentation fault". Also, the GetSecretCode function has...

  • **how can I make my program break if 0 is entered by user as last number...

    **how can I make my program break if 0 is entered by user as last number not always 10 numbers output should be enter 10 numbers:1 2 0 numbers entered by user are: 1 2 Largest number: 2 **arrays can ONLY be used in the main function, other than the main function pointers should be used #include #define N 10 void max(int a[], int n, int *max); int main (void) { int a [N], i , big; printf("enter %d numbers:",N);...

  • I'm trying to write a program in C that calculates the area of a rectangle. I...

    I'm trying to write a program in C that calculates the area of a rectangle. I need to have a function that gets dimensions from a user and stores them with pointers and addresses and another function that calculates the area... my question is how do i access that values from the dimension function so that I can use it in my calculation and main function.. for example. void userDimensions(float *base, float *height){ scanf("%lf" , base); scanf("%lf", height); } float...

  • I must call multiply, divide and remainder functions inside of SUBTRACT function.. I am stuck at...

    I must call multiply, divide and remainder functions inside of SUBTRACT function.. I am stuck at this point. Thank you #include<stdio.h> int getDifference(int a, int b); int main() { int a, b, result, multiply, divide, rem; printf("Enter the two integer numbers : "); scanf("%d %d", &a, &b); //Call Function With Two Parameters result = getDifference(a, b);    printf("Difference of two numbers is : %d\n" , result);    return (0); } int getDifference(int a, int b) { int c, multiply; float...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT