Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8648131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:14:36+00:00 2026-06-12T13:14:36+00:00

Whenever I run my code the variable bookcost changes itself to the value: 3435973836

  • 0

Whenever I run my code the variable bookcost changes itself to the value: 3435973836 .

It does this after it reaches the processingData function. I do not know why it keeps doing this! I have already written this program without functions and it worked fine 🙁 This is my second programming class, it is online and there is almost no support from the professor.

#include <stdio.h>

void inputData(int* inputs,int* booknmbr, int* nmbrpurchased, int* bookcost);
void processingData(int bookcost, int nmbrpurchased, int totalpurch, int costaccu);
void outputInfo(int booknmbr, int nmbrpurchased, int bookcost, int* total);

    int bookcounter = 0;
    int totalpurch = 0;
    int costaccu = 0;
    int totalcostaccu = 0;


int main ()

{
    int booknmbr;
    int nmbrpurchased;
    int bookcost; 
    int bookcounter = 0;
    int cycleRun;
    int total;
    int inputs;

    printf("Run Program? 1 for Yes or -1 for No \n"); // ask user to input product name
    scanf("%d", &cycleRun);
    while (cycleRun != -1) 
    {

        inputData(&inputs, &booknmbr, &nmbrpurchased, &bookcost);
        processingData(bookcost, nmbrpurchased, totalpurch, costaccu);
        outputInfo(booknmbr, nmbrpurchased, bookcost, &total);

        printf("Run Program? 1 for Yes or -1 for No \n"); // ask user to input product name
        scanf("%d", &cycleRun);
    }
}

void inputData(int* inputs, int* booknmbr, int* nmbrpurchased, int* bookcost)
{
    printf( "\nEnter the Book Product Number?\n" );
    scanf("%d", &booknmbr);

    printf( "Enter the Number of Books Purchased?\n" );
    scanf("%d", &nmbrpurchased);

    printf( "Enter the Cost of the Book Purchased?\n");
    scanf("%d", &bookcost);

    printf( "TEST: %u\n", bookcost);

    return;
}

void processingData(int bookcost, int nmbrpurchased, int totalpurch, int costaccu)
{
    int total;

    printf( "TEST: %u\n", bookcost);

    total = bookcost * nmbrpurchased;
    totalpurch = totalpurch + nmbrpurchased;
    costaccu = costaccu + bookcost;
    totalcostaccu = totalcostaccu + (bookcost * nmbrpurchased);

    printf( "TEST: %u\n", bookcost);

    return;
}

void outputInfo(int booknmbr, int nmbrpurchased, int bookcost, int* total)
{
    printf( "\nBook Product number entered is: %u\n", booknmbr);
    printf( "Quantity of Book Purchased is: %u\n", nmbrpurchased);
    printf( "Cost of the Book Purchased is: %u\n", bookcost);
    printf( "Total cost of books is: $%u\n", total);

    return;
}

void outputSummary(int bookcounter, int totalpurch, int costaccu, int totalcostaccu)
{
    printf( "\n\nNumber of records processed = %u\n", bookcounter);
    printf( "Number of books purchased = %u\n", totalpurch);
    printf( "Cost of the books purchased = $%u\n", costaccu);
    printf( "Total cost for all book purchases = $%u\n", totalcostaccu);

    return;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:14:37+00:00Added an answer on June 12, 2026 at 1:14 pm

    You’re passing the addresses of your variables to inputData … try this:

    /* not using inputs? */
    void inputData(int* pinputs, int* pbooknmbr, int* pnmbrpurchased, int* pbookcost)  {
        printf( "\nEnter the Book Product Number?\n" );
        scanf("%d", pbooknmbr);
        printf( "Enter the Number of Books Purchased?\n" );
        scanf("%d", pnmbrpurchased);
        printf( "Enter the Cost of the Book Purchased?\n");
        scanf("%d", pbookcost);
        printf( "TEST: %u\n", *pbookcost);
    } 
    

    You have a similar problem with total in outputInfo. You need to read carefully though your code and attend to details, paying attention to which variables are pointers and which are scalar values. It helps to name pointers differently, as I did here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Thanks in advance. This is my sample code. Whenever i try to run it
I'm trying to echo out a specific value, but whenever I run the code-
Whenever I run my code: $perl my_any_code.pl It always gives me this: perl: warning:
I want code to run whenever I create a new object. For example, see
Whenever i try to run sqlmetal, i get this: 'sqlmetal' is not recognized as
I am facing this issue whenever I am trying to run Play 1.2.1 in
What I want to do: run some prerequisite code whenever instance of the class
Whenever I run vm.runInThisContext(code, filename) , the code I ran reports __filename and __dirname
I am getting this error whenever I try to run GCC outside of its
whenever i run the following code it gives me NullPointerException. although i checking if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.