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

In your code:
The union uses OR
The intersection uses AND
I believe you'll find the difference uses XOR

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

Oh yeah, didn't notice that. char letters[6]; can only access [0] to [5] - 6 values int mem[3]; can only access [0] to [2] - 3 values

thomas_naveen commented: didn't notice mem[3] access. +1
jonsca commented: Excellent job too, I guess ;) +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I need to write a program that asks for the input of variables and one variable must be entered as "?", but I cannot get the program to use "?" at all. Also, I don't know how to create a driver function. Once I get the "?" input working, will the driver function just essentially be the equation I am given? Any help would be appreciated.

The answers depend completely on
* What you need to input
* How you are allowed to input it
* What the definition of 'driver' is to your instructor/boss
* What you need to accomplish

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
Random Letter 5: R
Random Letter 6: V
Random Letter 3: M
Random Letter 1: B
mem[0]=R
mem[1]=V
mem[2]=M
mem[3]=B

That's what mem[] contains

Before you use it :icon_rolleyes:

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

So, I figured out that I needed to make my private const variable into a public const variable, but how do I insert it into main?

What does "insert it into main" mean?

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

Are you having a problem you're not telling us or just asking a strange question that's hard to decipher?

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

Since you never initialized the mem[] array, try displaying it just to see what's in it. It could be anything, including 'R'.

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

My issues are:
1. How do I store the scores in arrays, then recall them?

You need to check your textbook for how to store values in an array and how to get the value. It's well defined in the chapter on arrays.

2. How do I prompt the user for 3 scores from 4 players before it prints the scores?

This should be the first thing you should work on.
First, write an input statement accept 1 score from 1 player
Next, put that in a loop to get 3 scores from one player.
Last, add another loop around all that for the 4 players.
You are now inputting 1 full bowling frame.
-- do not worry about the array above. Just understand the input.

Take each step one at a time, compile, run, repeat until each step works before moving on to the next step.
Now, add the idea of the array to keep track of each frame for each player.

What I am trying to do is input all the data into the array or if need me multiple arrays and then have them print

Use multiple arrays. Sort of.
Either 4 arrays for 10 frames for each player -- array[10]
or
One array for 4 players and 10 frames -- array[4][10]

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

I am running into multiple issues. I am not exactly sure how to go about rolling the dice,

Call rand() -- the value returned is one die roll.

summing them together,

Start with a value set to 0 as a total. Add the rolled die to it.

and how all the loops will work together for the desired output.

Think. Write the ideas on paper.
** Get one die (the computer only rolls 1 at a time).
** Roll it to the specifications of possible input
** -- 3 dice - 3 rolls;
** -- # rolls to check - 10 - repeat above 10 times. You don't want to try 10,000
** Write down each and every detail of how you are getting to an answer. When you understand that, you're ready to start coding.

Once again I am new to all of this.

Duh, ya think? :icon_wink: If you're having a hard time with simple tasks, you're new. That's OK. We all were once. No need to remind everyone.

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

You've got 87 lines of code. If we don't know which line has the error we can't suggest much.

When asking for help, provide all the details you can.

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

Since you are writing a student project on rolling dice, not solving universal chaos theory, rand() is more than adequate.

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

When i is 4 you are testing beyond the range of your array if ( in[i] > in[i+1] ) There is no in[5] as your code is using.

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

The pertinent and useful posts in this thread have been moved here. Maybe aianne can now start getting help without being railroaded into useless arguments. Keep it on topic. Go back to the other thread for arguing.

[edit]
Post ONLY help for aianne here. Continue the argument in the other thread. Posted here, they will be deleted.

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

Hey, if it works sometimes, it works. That's just a simple, logical fact.

Au contraire. If it only sometimes works, it's broken.

Do you work? If so,would you accept a $100 drop in pay this week because the payroll program only makes a mistake once in a while and doesn't add your hours correctly? After all, it is only once in 3 months...

Close enough doesn't work in computers.

jephthah commented: aha +6
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You use that if statement to test each year from your start year to your end year, and if TRUE, add one day to your total.

Keep in mind for the first year, if the date starts March 1 or later you don't check that year.

Also for the last year if the date is Feb 28 or earlier, don't check that year either.

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

by the way, this reply ws concerned with ancient dragon in order to handle the reply handed over to me by him....

Of course it was, and his response was spot on. Everything he said was correct. You should have not complained, and the proper response would have been "thank you for the correction" instead.

i have already specified that solution has only been submitted to the specific problem...so it wud be gud if u dont take it as a general case..i shall provide a suitable answer for the general problem...

Doesn't matter. Your solution was still broken.

And stop talking baby talk. This is a professional English-speaking forum. wud is not a word, gud is not a word, u is not a word. Use proper English. Read the Member Rules again.

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

fgets(buf, n, stdin) is just as easy as gets(buf) . It's more keystrokes but that is not a function of ease. It's also safer, that's why we recommend it. Too many people come whining to us with errors caused by gets() .

And no, if something allows errors to happen it doesn't work.

Salem commented: Nice +19
Aia commented: Worth pointing out. +8
Ancient Dragon commented: Absolutely +27
iamthwee commented: I wet myself when I read this. +11
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Look up exactly how the switch()/case statement works.
Look up how string type works when passing/returning using functions.

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

well if u r that smart to understand it, u must also realize that the solution was given to the exact problem... the array can always be declared according to the size of input dynamically...

P.S. if u hav a solution , post it..dont just sit around and mock at others...utilize the spare tym elsewhere... :)

No, if you have a solution, do NOT post it. Help the person figure it out for himself using guidance from your greater knowledge.

We understand "the solution was given to the exact problem" and that is the problem. People learn nothing by turning in your code for their homework.

And as the Dragon said, your program is wrong.

char rs[3];//array to store the reversed string

What if the string is "Hello"? How do you stuff 6 characters into these 3? Broken code.

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

Actually, using strcpy() over the same buffer is not defined. See section 2.14.13 strcpy here. Also here and here.

You need to copy into a different buffer.

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

my almost works but for some reason after i look up the product it checks each value inputted in the array. How do I get it to find the specific item in the array?

Your last loop prints out "not found" for every item that doesn't match. In reality, that else statement should be "isn't the item wanted" to be accurate. And with that knowledge, is it a useful thing to display?

Your assignment (as posted) does not mention sorting, so it's really not necessary. A linear search is not enhanced by sorted values.

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

Ok i can do it already. But here's what I want to know:
You can actually assign values to an array just by putting a space in between numbers/digits? what is the logic or understanding behind it?

How can you tell if 3756 is 3756 or 3, 7, 5, 6? If you can't, neither can scanf() . Therefore, use the format it understands.

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

To put this in perspective, the habanero pepper (previously the hottest pepper) is a measley 100,000–350,000 Scoville units.

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

Not easily. scanf() is notoriously ill-mannered.

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

Read the entire input in one line with fgets() . Then check the input to make sure it is in the correct format. If not, do what you need to do. If so, convert the character digits to numbers for n1 & n2 and move the letter to lett

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

Even though what you want to do makes no sense,

1- Use lseek() to get to the end of the file.
2- lseek() back one character
3- read the character
4- repeat 2&3 until you get to the beginning of the file

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

Please decipher this statement as it pertains to coding:

You need different index values because you are removing characters so the indices will not be identical once punctuation is found.

What is an index value?
What are indices?
Pertaining to the program you wrote, how did you 'remove punctuation'?
Anything else you can explain?

I'm asking because in programming you must figure this stuff out. These are very simple (you will agree in another week, believe me) ideas.

Try doing this on paper. Write down your sentence. Copy each valid character one at a time and keep track of the character position in each sentence. When you understand the technique on paper, how do you tell the computer to do exactly what you just did? After all, you are a computer too.

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

I created a program like this

#include <stdio.h>

main()
{
 /* Declare variables */
 char word[] = " ";

        printf("Enter a word: ");
        scanf("%s", &word);

        printf("The word entered is %s\n", word);
}

It compiles and runs as I had intended.

Then you're very lucky. Almost any input you use will blow out your array, overwriting memory you don't want to touch. char word[] = " "; defines an array of 2 characters (one SPACE, one '\0'). Enter 3 characters and you overwrite data that's not part of the array.
You need to specify a value for the array size: char word[120] = " "; which means you can enter up to 119 characters followed by the necessary '\0'.

But now how would I go about reading and printing each character of the input word?

Depends on if you want to output one character at a time, or the whole word at once. Please think about how to do either.

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

Who's/which idea did you use? It doesn't look like any of our suggestions.

If it was jonsca's, your arrays are equal in size and he distinctly said

You know the new array will be less than or equal to the old one in size.

You need different index values because you are removing characters so the indices will not be identical once punctuation is found.

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

You need to input multiple digit numbers, right? So you need arrays for your data. What's the largest number you want to handle? Create arrays at least that large.

The way I did it is have 1 input array (char) and 3 calculation arrays (2 number and 1 answer)

1) Set all the calculation arrays to 0's
2) Input one entire number into the input array
3) Starting at the end of the input number, move and convert each character into the first number array, starting at the end moving to the beginning.
4) Repeat for the next number

Example -- if all arrays are 10 long, and your first number entered is 163, input[2] (the '3') => num1[9] (as 3, not '3')
Continue with input[1] (the '6'), etc.

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

Character array.

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

Where you put

for(int k=1;;k++)

i do not need a second value? So I can just skip it so that it stops on its own without me telling the loop when to stop?

This is an infinite loop. It will not stop on it's own. Somewhere in the loop you will have to break; out of it.

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

Easy way:
Copy the string a character at a time into another string in a loop. Don't copy the punctuation.

Harder way:
Set up two indices, one (indOrig) for pointing at the original string, one (indNew) for pointing at the new character position. Both start at 0.

During your loop,
1) copy the character from the indOrig position to the indNew position.
2) increment indNew for every non-punctuation character.
3) increment indOrig for every character.
Be sure you loop far enough to copy the trailing \0

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

You can't do exactly what you want. Compromise. Enter 5 1 2<enter>

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

Assume score input is 30,40,50,60,70.
In your FOR loop, when quiz == 0, what value is element grade[quiz-1]?

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

You need to break in the switch after every grade, or it will go through it no matter what.

Aia got confused with your non-standard syntax as I almost did:

switch(ch)
              {
                 case 'a': 
                 case 'A':a++; break;
                 case 'b': 
                 case 'B':b++; break;

'Proper' (less confusing) syntax is:

switch(ch)
              {
                 case 'a': 
                 case 'A':
                         a++; 
                         break;
                 case 'b': 
                 case 'B':
                         b++; 
                         break;
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Do you know how to use the % operator? You can take your integers and split them into 3 digits which can be converted into characters.

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

Other than c being use to accept input and count the number of 'c's, I seen nothing wrong.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
int num[8];
	for(i=0;i<l;i++)
	{
		if(isdigit(ss[i]))
		num[i]=ss[i]-0; // I did not say subtract 0, did I?
	}                       //  What good does subtracting 0 do?
}

When you create num it's loaded with garbage. If you don't load a value into an element, garbage remains.

But why would you create a num value for all ss values? Didn't you say there are only 4 integers to convert? Use a different index for num instead of i.

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

I created the program to obtain input from a user instead. The program compiles, but when I run it, it get stuck at the function call in my while loop in main. I can't seem to figure out what's wrong with my function?

Since we can't see your screen, "it get stuck" is too vague. If you give us details for complete understanding, you wouldn't have to wait hours for a fix.

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

Did you actually try to read the first 4 numbers on one line? That wold be your first job. Just try something. If it doesn't work, we can help. If it does, you don't need us, nor the big wait time (1.5 hours for this one) waiting for an answer.

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

I'll give you that one :)

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

Yes, I am fairly familiar with the getline function, but not so much with getting a line from a text file.

Do you have a problem with tutorials, text books, and Google? That is where you do the first level of learning. We are here to fine tune what you failed to understand. We are not teachers.

Your question is a first level question. Look it up. Try it out. When it doesn't work, that's where we come in...

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

One Enter is all that is needed. Enter 5 numbers separated by spaces, then press Enter once. See code below.

As I said...

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

alphabet from lower to upper , using ascii
what logic should be use to convert small letters into capital using ascii codes??
for example ascci code for A is 65 and ascii code for a is 97
how can i coonvert from integers to character ?

Such confusing responses....

What is the difference (numerically) between 'A' and 'a'?
What about 'B' and 'b'?
'C' and 'c'?
Notice a pattern?

Therein lies your logic for conversion.

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

Code Blocks has plenty of graphics. It provides integrated support for modern, cross-platform, industry-sanctioned graphic libraries, like GTK+, OpenGL, Win32::GUI, and wxWidgets.

not this archaic kid's toy of <graphics.h> used only by children, DOS Luddites, and university students from the Subcontinent.

In other words, no, it doesn't have graphics. And it's also not what the instructor requires. So -- get an A and use the compiler the instructor wants, or get an F for using a compiler that's not authorized and spend 3 weeks getting a graphics package installed and learning how to draw a point.

Please understand that Turbo, no matter how old
1) is in use
2) works
3) is not going to get replaced because you don't like it.
And stop regurgitating hatred for something you've go no business even commenting on. It's getting old.

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

I doubt it was merely a coincidence. It was in fact well planned, with whatever differences designed for input vs. output.

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

I am using c++ and need to devise a method to determine the check digit of a credit card. The user enters the card no. as a string. The card no is then divided into blocks of length, x. these blocks are then added.
I have the code to convert the string into and integer, however i am stuck at how to divide the string into consecutive blocks. Logically, i think i must first divide the string into these blocks then convert those smaller strings into integers.

You've got it. Convert 4 characters into an integer. Then convert the next 4. Simple.