×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

No laughing at the newbie questions!

No laughing at the newbie questions!

No laughing at the newbie questions!

(OP)
Hi all,

Ok, dumb question time. Take a look at the code below, (ignoring the crap layout, etc). The program itself works except for a few glitches.
1). I want the user to be able to press Q to quit the loop and get the results. This was working at the start but obviously I've screwed something up and now it doesn't.
2). I would like each of the results printed on a seperate line instead of a stream of text and results with no spaces
3). When coding, what symbol is used to enable me to run the text over to the next line without C++ thinking that its the next piece of the program?
4). Last one. At the moment this program is stuck in the loop, everytime I enter the age of the client I get the results(?)
As I said, these are very dumb questions & I'm certainly no programmer, this is for a compulsery course I'm doing.
Thanks for your time.

int main(int argc, char* argv[])
{
char claimed;
int claim;
int age;
int u25;
int returns;
claimed = '*';
claim =0;
u25 = 0;
returns = 0;
while (claimed != 'Q')
{
claimed = ReadCharPr("Has the client claimed within the last 12 months? ");
age = ReadIntPr("Age of client: ");
if (claimed != 'Q')
{
returns = returns + 1;
}
if (age < 25)
{
u25=u25 +1;
}
if (claimed == 'Y')
{
claim = claim + 1;
}
WriteIntPr("Number of results analysed = ", returns);
WriteIntPr("Number of claimants = ", claim);
WriteIntPr("Number of claimants under 25 = ", u25);
}
  getchar();
        return 0;
}

RE: No laughing at the newbie questions!

(OP)
Well, I knew they were dumb questions and after a few more hours of fiddling, I fixed all but question 2. So how can I get the results printed on a line of their own instead of just one after the other?

RE: No laughing at the newbie questions!

I think the symbol to go to the next line is a slash followed by an n... "/n" or it might be a backslash... "\n"

also, when using cout endl is also used:

cout endl;

I don't know much either, but I hope that helps...

~Trooper_Max~

RE: No laughing at the newbie questions!

Ok... I'm now pretty sure that it is a backlash followed by and n... "\n"

So I'm guessing if you do something like this in the section that writes the results it will work... :

WriteIntPr("Number of results analysed = ", returns);
WriteIntPr("\nNumber of claimants = ", claim);
WriteIntPr("\nNumber of claimants under 25 = ", u25);

But I don't really know... I hope that helps you...

~Trooper_Max~

RE: No laughing at the newbie questions!

(OP)
Thanks Trooper_Max,

I found it in another newsgroup. If you're intrested, the revised code follows:

I needed to #include <fstream.h> in the headers.

WriteIntPr("Number of results analysed = ", returns);
printf("\n");
WriteIntPr("Number of claimants = ", claim);
printf("\n");
WriteIntPr("Number of claimants under 25 = ", u25);
printf("\n");

Thanks for the suggestions anyway.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close