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

  • Thread starter Thread starter ineedhelpnow
  • Start date Start date
  • Tags Tags
    Years
Click For 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.
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 15 ·
Replies
15
Views
4K
Replies
12
Views
3K
Replies
3
Views
1K
  • · Replies 2 ·
Replies
2
Views
9K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 22 ·
Replies
22
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 13 ·
Replies
13
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
1K