C/C++ Print US Presidential Election Years Since 1792

  • Thread starter Thread starter ineedhelpnow
  • Start date Start date
  • Tags Tags
    Years
AI Thread Summary
The discussion focuses on modifying a C++ program to print U.S. presidential election years from 1792 to the present, emphasizing the need for a while loop and the use of "<=" to prevent infinite loops. Participants express frustration over a lack of effort in understanding the code, urging the original poster to attempt the task independently. Suggestions are made to manually write out the election years to better grasp the logic of the program, encouraging a step-by-step breakdown of the process. The conversation highlights the importance of engaging with the material and developing problem-solving skills in programming.
ineedhelpnow
Messages
649
Reaction score
0
Modify the program to print the U.S. presidential election years since 1792 to present day, knowing such elections occur every 4 years. Don't forget to use <= rather than == to help avoid an infinite loop.

Code:
#include <iostream>
using namespace std;

int main() {
   int electYear = 0; 
   
   electYear = 1792;
   // FIXME: Put the following in a while loop 
   cout << electYear << endl;

   return 0; 
}

how do i do this?
 
Technology news on Phys.org
ineedhelpnow said:
Modify the program to print the U.S. presidential election years since 1792 to present day, knowing such elections occur every 4 years. Don't forget to use <= rather than == to help avoid an infinite loop.

Code:
#include <iostream>
using namespace std;

int main() {
   int electYear = 0; 
   
   electYear = 1792;
   // FIXME: Put the following in a while loop 
   cout << electYear << endl;

   return 0; 
}

how do i do this?

Do.. do you have any thoughts on the matter at all? I'm asking because most if not all of your C++ questions lately have been of the form "here is some code, how do I implement this". You need to at least give it a try.
 
i know. i have been trying to understand. but these last lessons we've been going over make no sense to me. I am trying to understand but its all fuzzy. most of the ones I've been posting lately also arent homework problems. they are just activities.
 
Bacterius said:
Do.. do you have any thoughts on the matter at all? I'm asking because most if not all of your C++ questions lately have been of the form "here is some code, how do I implement this". You need to at least give it a try.

She is clearly giving it a try, don't be so hard on her, I'm sure you also encountered issues when learning C++ and had people there to help out.
 
ineedhelpnow, imagine that it's now 1815 instead of 2015. Could you do manually what you need the program to do, i.e., write election years until 1815? While doing it, think carefully about what steps you are performing. Are you adding numbers? Are you comparing them? How do you know it's time to stop? Can you do this if you have only limited space to write numbers on paper, but you can erase old numbers and write new ones in the same space?

After you do this, try to describe the sequence of steps you had to perform and post this description.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

Replies
5
Views
3K
Replies
22
Views
3K
Replies
3
Views
3K
Replies
13
Views
2K
Replies
4
Views
3K
Replies
1
Views
1K
Back
Top