Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

No laughing at the newbie questions!

Status
Not open for further replies.

Callahan

Technical User
Nov 21, 2001
174
GB
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(&quot;Number of results analysed = &quot;, returns);
WriteIntPr(&quot;Number of claimants = &quot;, claim);
WriteIntPr(&quot;Number of claimants under 25 = &quot;, u25);
}
getchar();
return 0;
}
 
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?

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

also, when using cout endl is also used:

cout endl;

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

~Trooper_Max~
 
Ok... I'm now pretty sure that it is a backlash followed by and n... &quot;\n&quot;

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

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

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

~Trooper_Max~
 
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(&quot;Number of results analysed = &quot;, returns);
printf(&quot;\n&quot;);
WriteIntPr(&quot;Number of claimants = &quot;, claim);
printf(&quot;\n&quot;);
WriteIntPr(&quot;Number of claimants under 25 = &quot;, u25);
printf(&quot;\n&quot;);

Thanks for the suggestions anyway.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top