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.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Thread 'Project Documentation'
Trying to package up a small bank account manager project that I have been tempering on for a while. One that is certainly worth something to me. Although I have created methods to whip up quick documents with all fields and properties. I would like something better to reference in order to express the mechanical functions. It is unclear to me about any standardized format for code documentation that exists. I have tried object orientated diagrams with shapes to try and express the...

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