I have this pseudocode for a if then else program:
input
display a message asking user thier age
get the users age from the keyboard
display a message asking user for thier friend's age
get the users friends age from the keyboard
processing
none
output
if age_user greater than 39
display "You are over the hill."
else
display "You are still young."
endif
if age_friend greater than 17
display "Your friend can vote."
endif
if age_user equal to age_friend
display "You and your friend are the same age."
display "You should celebrate together."
else
display "You and your friend are not the same age."
display "You should party together anyway."
endif
pause so the user can see the answer
******************************************************
Potential Variables
Data Type Identifier Name
********* ***************
integer age_user
integer age_friend
I did write my code, but it's not working. For example, I typed 11 when it asked for the user's age and then 12 for a friend's age...After executing the program, I got the message that the two people were the same age along with other messages. I must be missing something or wrote the code wrong somewhere....
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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
// Headers and Other Technical Items
#include <iostream>
using namespace std;
// Function Prototypes
void pause(void);
// Variables
int age_user;
int age_friend;
//******************************************************
// main
//******************************************************
int main(void)
{
// Input
cout << "\nEnter your age here --->: ";
cin >> age_user;
cout <<"\nEnter your friend's age here --->: ";
cin >> age_friend;
// Process
//None
// Output
if (age_user > 39)
{
cout << "You are over the hill.";
}
else
{
cout << "You are still young.";
}
if (age_friend > 17)
{
cout << "Your friend can vote.";
}
if (age_user = age_friend)
{
cout << "You and your friend are the same age.";
cout << "You should celebrate together.";
}
else
{
cout << "You and your friend are not the same age.";
cout << "You should party together anyway.";
}
pause();
return 0;
}
//******************************************************
// pause
//******************************************************
void pause(void)
{
cout << "\n\n";
system("PAUSE");
cout << "\n\n";
return;
}
//******************************************************
// End of Program
//******************************************************
|