sentinel looping

write a program that will prompt for and receive your age in years and months and calculate and display your age in months.if the amount is more than 500, three asterisks should appear beside the month figure. your program is to continue until a sentinel of 999 is entered?

need your help
Last edited on
What with?
write a program that will prompt for and receive your age in years and months and calculate and display your age in months.if the amount is more than 500, three asterisks should appear beside the month figure. your program is to continue until a sentinel of 999 is entered?

i don't know how to write this program an its for my homework please help me i am a beginner.
...what is the part you're having problems with? We can't read minds.
i just dont know how to write the program in c++ this where i am? i dont think i am correct at all. just write it so i can see how it is done.



#include <iostream>
using namespace std;

int main()
{
int age = 0;
int month = 0;
const int sentinel = -999;

cout<<"Enter age in years (-999 to end input");
cin <<age;

//inputs items

cout<<"Enter age";
cin>> age;
cout<<"Enter month";
cin>>month;

Actually, that's more or less correct, except the cin << age; line - that one needs to go. The closing quotation mark in line 10 is at the wrong place too.
Now you just need one more line to print the result and a closing brace for main().
Last edited on
i cant move from here what is the next step. my teacher told me to include a while statement in the program. why cant u just write the program for me so that i can see the steps in detail please.
I still don't know why you're having problems with that last remaining step, but okay:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
using namespace std;

int main()
{
  const int sentinel=-999;
  for (;;)
  {
    int age,months;
    cout << "Enter age in years (" << sentinel << " to end input): " << flush;
    cin >> age;
    if (age==sentinel)return 0;
    cout << "Enter months: " << flush;
    cin >> months;

    const int ageMonths=age*12+months;
    cout << "Your age is: " << ageMonths;
    if (ageMonths>500)cout << "***";
    cout << " months" << endl;
  }
}
thank u so much remember i am beginner hoping to reach your level soon, thank u so much.
Don't forget to include a while loop if your teacher specifically wants one.
Topic archived. No new replies allowed.