WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

It doesn't work because line 4 doesn't do anything. This function will convert the entire sentence to all upper-case. Hope that's what you want to do.

Or simplify with

void printSentence(char *sentPtr){
    char *sent = sentPtr;
    while(*sent)
    {
       *sent = toupper(*sent++);
    }
    *sent++ = '.';
    *sent = 0;
    cout << sentPtr << endl;
}

toupper() by definition only sets lower case letters to uppercase and will leave all other characters alone.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Rule of thumb -- if you need both, use && (and). If you need either, use || (or).

Test it by using English (or your native language): is it "if != Q or q" or is it "if != Q and q" and you get the operator to use.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Is your task to input a file name, and convert the filename itself to upper case? Or are you supposed to
1) open the file
2) read the file
3) convert the contents of the file to upper case?

And if you don't take the hint on gets() , we may stop helping you :icon_wink:

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

function printSentence at line 98: you have to save pointer sent before executing lines 100 thru 102, then use the saved pointer in line 103 because as written that function is destroying the value of the pointer.

do you mean something like this:

void printSentence(char *sent){
	*sent = toupper(*sent);
	while(*++sent);
	*sent++ = '.';
	*sent = 0;
	cout << sent << endl;
	return;
}

?

Isn't it modified by address therefore its modified permanently? I was having it just point to itself. I wrote the function to return a value but i figured since it modifies the string anyway I don't need it to return a value. I just left the return in there in case I want to reuse the code later.

No. All you did is change the first character to upper case. At the end of the function sent point to the end of string where you loaded a 0. Outputting it now simply outputs a null string.

You need to copy the pointer in sent to another variable and use that variable to do your changing. Leave sent alone so it still points to the beginning of the string for outputting.

And it's perfectly acceptable to use a return at the end of a function. It actially helps readability.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

for some reason my program now only prints once character before prompting for a user response, though it was working before. im not too sure why...

You have a dozen printf() 's and some puts() . Can you be a little more specific?

Also, see this about your scanf() .

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

what do i do when the years are not the same? i need to be able to change the years

That has already been answered.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

when the program prints the answers to the txt file, it doesnt print the string but instead prints gibberish. any idea how to represent that string so that it is equal to char rt?

So what do you think these lines do?

rt=="A) 1";
rt=="B) 2";
rt=="C) 3";
rt=="D) 4";

Is this how your book recommends loading a string into a variable?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

-------------------Configuration: Test - Win32 Debug--------------------
Compiling...
myfiletesting.c
C:\Documents and Settings\HP_Administrator\myfiletesting.c(16) : warning C4029: declared formal parameter list different from definition
C:\Documents and Settings\HP_Administrator\myfiletesting.c(28) : warning C4028: formal parameter 1 different from declaration

Look at the lines specified. You are calling a function, but the parameters do not match the prototype you specified, such as calling with a char and the parameter needs a char*

C:\Documents and Settings\HP_Administrator\myfiletesting.c(44) : error C2198: 'PopulateArray' : too few actual parameters

Isn't this one obvious?

C:\Documents and Settings\HP_Administrator\myfiletesting.c(44) : error C2059: syntax error : ')'

Look at the line. Why would the errer point out a ')'?


-------

The following code should do the trick. Its not the most elagnant code as there is no validation for user inputs.

What grade are you expecting for finishing his code for him? We prefer to help them solve the problems, not prove we can do better... :icon_wink:

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Simple loop with a test inside.

would it be a for loop with an if statement?

Duh.... :icon_wink:

for every year between one and the other, use my leap year function to test if each year is a leap year and for every year that its true, add one day?

Yes.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

how should i improve my formatting, can you please give me an example... i just get lost of what has to be where when im writing

Here's a turotial on Formatting C / C++ code

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

:icon_rolleyes:
So you didn't bother with my questions at all and just made a convoluted while statement? Then all you can say is "something is wrong -- go find it and tell me what to do"?

I don't think so...

I realize you're probably frustrated (so am I), but if you had followed my posts you might have learned something about how to debug your code.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Neither can we. You need to format your code, and use CODE tags.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

First things first -- put braces around everything that needs them -- around statements contained in if s, else s, switch es, for s, etc. And indent them properly. Then we can see what's going on.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Look at the do-while . What causes the loop to exit?
Then look at the if with the continue . Is there a correlation?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

How about the Dev-C++ website?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Use a loop to generate as many random numbers from 0 to 25 as you want and add the values to the string. When you get the random number, simply add 'a' to it and you will have all letters instead of 0-25

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Close, but not close enough. You'd get the same answer if the years were 2001-2005 and 2004-2008 but in fact the former has one day les because there's only one leap year. You need to look at each year individually and deal with LY. Simple loop with a test inside.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Good day.

G'day, mate!

I have a few questions. I wanted tge program, each time a customer chooses an item, for it to be displayed as he/she chooses. It's also telling me that index is undeclared.

Please be a little clearer. Your first question has an obvious answer, therefore I must be interpreting it wrong. The second doesn't make sense unless it's a compile error. And you know enough to post the what and where the error is if that's what the problem is. So that can't be it, either.

And haven't we mentioned formatting your code at least once? Or was that someone else?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Unresolved external means the variable being used does not exist. It was never defined at the spot you are attempting to use it.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Don't double post

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Yeah. As far as I am concerned, the computer is there to serve me, not the other way around. ;)

Then why are you using WinBlows? :icon_twisted:

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

First figure out why the loop exits. Then before the continue , defeat the exit condition.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Maybe you need to read the post titled Read Me: Read This Before Posting

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Ahhh, code gremlins strike again!!!!

Sounds like you still have a problem -- and I'll bet gets() has something to do with it. You are probably overrunning an array somewhere. Like entering 10 or more characters into a character array defined as 10...

Might want to check your code over very carefully.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
Salem commented: Quite so. +11
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Shouldn't continue in my else statement return me to the top do...while loop and print the following again?

Sorry, my mistake. No, the continue sends you to the bottom of the loop.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Add all the characters?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

So what was the problem? How did you solve it? Your answer may help someone else later.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I believe so.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I have, i done this before i posted this question! it says that the boolean expression is used to test condition to determine when the loop should terminate. The test condition must always involve comparing the value of the counter variable with some numerical limit. Which in this case was

but im unsure still.
should i use a true false statement ??

In the for statement you posted for(int i = 0; students[i]; i++) , what is your comparison statement? What is it comparing?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Did you miss the information about CODE tags? If so, just read the background on the box you typed your message in.

If binary is 2, hex is 16, and octal is 8, what do you think you need to change in the code you posted?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Better yet, look at gabbly.com. As it says on the homepage,

Just add 'gabbly.com/' in front of any URL

and you can chat with whomever does the same thing...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

OK, I looked more closely at your code. I made an assumption before.

#1) I see you're still using the getch() , clrscr() , and the evil gets() . Bad. Very bad. You're writing C++. Stop using C.

#2) In the loop, the code

if(stricmp(xyz.getname(), name)!=0)
{
...
}
if (stricmp(xyz.getname(), name)==0)
{
...
}

is the same as

if(stricmp(xyz.getname(), name)!=0)
{
...
}
else
{
...
}

Use the else version -- it's easier to read.

You're saying the code you posted isn't working? Then add some output statements to watch the program's flow and see where it seems to be going wrong.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Do what I said, please

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Did you read and write the rest of the file? Or did you think the records past the last one you read would magically move over to the new file? :icon_wink:

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

sorry i have not read strings yet so didnt know...
can you tell me more about that??

thanx...

Then wait until you read about strings.

Until then use strcmp() or strncmp() which works for your definitions.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Look up the definition of a for loop. What do each of the parts of the loop do? Do your parts comply?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Where are you calculating the grades?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

It however, gives me:

1>Compiling...
1>grading.cpp
1>c:\users\documents\visual studio 2008\projects\grading\grading\grading.cpp(34) : error C2059: syntax error : ']'

This was in reference to(which is in the main function) :

check_correct_answers (answerKey[] , studentAnswers[] , grade, score);

Change it to check_correct_answers (answerKey , studentAnswers, grade, score); When passing an array, just the name is necessary.

You must call the functions when you have data. You can't call the functions willy-nilly just to get them in the code.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

... or string name[100]; You don't seem to have a read loop defined yet.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Yes, they are there to provide you with the answer. Just because you buy a bread machine does not mean you always have bread ready. You have to actually use the thing first. Where did you use the functions...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You need to read each line. The \n\n will take two lines. You can tell the second \n because the line will be extremely short. == may not be good, but < might work better. Depends on how consistent the blank lines are -- extra SPACEs for example.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Try using a while look for the first loop instead. A for loop implies you know how many times you need to go through the loop. A while implies you exit the loop when some criteria is satisfied, such as you reached the end-of-file ( EOF ).

Since you seem to know code tags, you should be aware that for really good help you need to post your code... :icon_wink:

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Try commenting your code:

getline(inFile, answerKey);           // Get the answer key

   cout<<"The correct answers "<<answerKey << endl<<endl;
   while(getline(inFile, studentID))     // Read student ID
   {
     cout << studentID <<" ";            // display the current student

     getline(inFile, studentAnswers);    // read the student's answers
     cout << studentAnswers << endl;     // Output the answers
   }
	return 0;
}

What seems to be missing?

And you still need to work on your formatting.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

by the way why dont you use getch() at the end of the main function. It will wait for the user to press enter before the program closes.

you have to include header file conio.h for that

int main ()
{
    int a;
    
    cout << "Hello World";
  
    cin>>a;
    getch();

}

Because it's not portable. It's not part of standard C/C++. Why not just use a C++ function, like cin >> dummy; or a call to getline()

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

i've enumerated the months with the number of days in each month

how do i rig it so that what ever the user types for their two months counts the number of days in the months between? could i use a for loop like:

for (int i=first month; i<last month; i++)

my brain is fried

-___-

Sort of. If you don't want the first month added use for (int i > first month; i < last month; i++) But, what if your dates are 15-Sep-2006 to 22-May-2007?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

CGI stuff can coded more quickly in perl and php

Immaterial. You develop programs in the language
1) your skillset lies
2) your boss wants it developed in
3) you decide is necessary to develop the code

I agree PHP and Perl may be better, but to suggest it to someone that is developing a system in another language is IMO a rude suggestion. It the same as suggesting a student use vectors when they are learning (or barely understand) arrays.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

>gets(name);
http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1049157810&id=1043284351

Yes, gets() is a very dangerous function, as is scanf("%s",...) in exactly the same way.

>clrscr();
Non portable

As is getch() . Best to remove conio.h completely and use no functions from it because most compilers won't be able to compile your programs.

>while (!fil.eof())
Doesn't work as you expect it.

For further information, see this, .eof() is exactly like feof()

Modification of a file would be better achieved by creating a temporary buffer with all the changes then overwrite the original file.

Another alternative is to simply write each record to a new file. When done, the program can delete the original file and rename the new file. This will also save all the file pointer stuff you're doing now, making the code much simpler and safer.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Thanks a lot, may I ask what was the std:string line; ...

Define the variable line as a string variable

... and the getline(cin,line) for?

get a line ( getline() ) entered from the keyboard up to the \n and put it in the variable line.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

That is quite messy.
Better move to perl/php

Yes, it's quite messy because you used TABs for indentation instead of 3-4 SPACEs. Outside of that the formatting seems fine.

And moving to Perl or PHP is one of the most asinine suggestions I've ever heard. Why would someone want to develop a C++ program in Perl or PHP?