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

  • Home
  • SEARCH
  • 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 4104138
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:04:50+00:00 2026-05-20T21:04:50+00:00

For an assignment we are supposed to read in a list of dates and

  • 0

For an assignment we are supposed to read in a list of dates and associated values (temperatures) from a text document. Values in each line are separated by commas.

Example data:

dd,mm,yyyy,x,y,z,w
01,01,2011,1.1,5.2,6.5,7.5
02,01,2011,2.1,5.2,6.1,1.1
03,01,2011,4.5,2.5,6.1,2.1
...
30,01,2011,4.1,6.1,6.1,2.1
01,02,2011,2.5,6.1,7.1,6.3

So far I have implemented a loop to read each line:

while(scanf("%d,%d,%d,%f,%f,%f,%f", &dd, &mm, &yyyy, &x, &y, &z, &w) == 7)
{
}

We’re given the assumption that there are no errors in the document, and no duplicate dates.

However, there may be missing entries (not each month have complete data; missing days).

I am having trouble detecting if each month’s data (mm) is a complete month or only a partial month.

Eg: 31 days in March 2011. If I have 31 entries from March, I need to print ‘Full month’, otherwise if there are missing days I have to print ‘Partial month’.

So far I have been using if(mm==1){} statements to separate each month inside the while(scanf(...)) loop and then incrementing them in separate variables, then comparing it with the amount of days in a complete month, but I don’t know how to implement it so it detects that mm has changed from the previous line (new month) and perform a certain action (e.g.: calculations)

Sorry if this is confusing!

We have not been taught arrays yet, only operations, loops and functions.

  • 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-05-20T21:04:51+00:00Added an answer on May 20, 2026 at 9:04 pm

    keep prev month value somewhere; finalize monthly related computations and reset the monthly counters when the month you are reading is higher than prev month

    int curmonth = 1;
    int dd,mm,yyy;
    float x,y,z,w;
    float xtotal = 0,ytotal = 0,ztotal = 0,wtotal = 0;
    while(scanf("%d,%d,%d,%f,%f,%f,%f", &dd, &mm, &yyyy, &x, &y, &z, &w))==7 {
        if (mm == curmonth) {
            //add to current counters
            ztotal+=z;
            ytotal+=y;
            xtotal+=y;
            wtotal+=w;
        } else {
            if (mm < curmonth) 
                //not the expected order as per specs so better die now
                exit(1);
            printf("month=%d,my_calculations=%f,%f,%f,%f\n",xtotal,ytotal,ztotal,wtotal);
            xtotal = ytotal = ztotal = wtotal = 0; curmonth=mm;
        }
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assignment: Write a C++ program to read the menu information from menu.txt. First letter
So for an assignment I have to read from a input file that is
So I have this assignment where I read in 1 line at a time
I having some trouble with an APCS assignment. The program is supposed to read
I wrote a program for an assignment which is supposed to print its output
I am supposed edit some code for an assignment, and he gave us the
I am working on an assignment for networking where we are supposed to create
I'm working on a small homework assignment and I'm supposed to make a food
I'm working on an assignment where i am supposed to display grocery items in
I'm working on a homework assignment for CS1, it's supposed to bring us back

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.