Disclaimer: I am a student taking an intro to programming. I have some experience in Python because that's what I'll be using/have used in the Geographic Information Systems industry. I recently went back to school to make my knowledge in GIS official. I do enjoy learning C++, but this has me frustrated!
I looked through this thread and couldn't find a similar topic. My instructor saw fit to do most of his examples in C++. I do not need a solution to my problem, just guidance. The first question relates to the example code in my online module:
1 2 3 4 5 6
|
counter = 0;
while (counter < 5)
{
cout << "\nI love computers!";
counter ++;
}
|
In the fifth line, there are two plus signs after the 'counter' variable. Why?
My second question has to do with the simple code we are to turn in tomorrow. The cout is a silly line "I love computers!" I cannot get it to print on my screen. The pseudocode my professor gave us to write our code from reads like this:
output
if age greater than 17
display "You can vote."
else
display "You can't vote."
endif
counter is assigned 0
while counter is less than 5
display "\nI love computers!"
increment counter
endwhile
pause so the user can see the answer
The 'if then else' part works fine in my code, but the I love computers never shows up. Is there something missing from this pseudocode? I am using a Dev-C++ Bloodshed compiler and it turned in no errors after I ran it.
Could someone point me in the right direction? I tried to use a simple header file with pause, delay, and clear screen functions. I'm wondering if clearing the screen after the 'if then else' part runs, but there is no input afterward. Below is what I have so far, I'm sorry if I posted too much information, I am new at this!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
#include <iostream>
using namespace std;
// Function Prototypes
void pause(void);
// Variables
int age;
int counter;
//******************************************************
// main
//******************************************************
int main(void)
{
// Input
cout << "\nHow old are you? --->: ";
cin >> age;
// No Processing
// Output
// Endif
if (age > 17)
cout << "You can vote.";
else
cout << "You can't vote.";
pause();
return 0;
//While
counter = 0;
while (counter < 5)
cout << "\nI love computers!";
counter ++;
pause();
return 0;
}
//******************************************************
// pause
//******************************************************
void pause(void)
{
cout << "\n\n";
system("PAUSE");
cout << "\n\n";
return;
}
//******************************************************
// End of Program
//******************************************************
|