Friday, July 31, 2009

C Programming Question (Printing Data in Columns)?

Below is my program. I have the two arrays print, but I want it to look good. I want it to print 3 rows like below, except aligned (Male being an array, female being the other array, and Age I would probally just do a variable set w/ age = 0 and each for statement on the output does age+1. Need to know how to do all this output? Thanks





Age Male Female


0 0 0


1 0 0


2 0 0





#include %26lt;stdio.h%26gt;


#include %26lt;math.h%26gt;


#define n 101





main(){





int male[n], female[n],i;


for (i=0; i%26lt;41; ++i)


male[i] = female[i] = 100;


for (i=41; i%26lt;101; ++i)


male[i] = female[i] = 0;





//PRINT MALE AND FEMALE ARRAYS (AGE 0 to 100)


printf("Female Array\n");


for(i=0; i%26lt;n; i++)


printf("%d\n", female[i]);


printf("Male Array\n");


for(i=0; i%26lt;n; i++)


printf("%d\n", male[i]);





return(0);


}

C Programming Question (Printing Data in Columns)?
Put a number between the % and d so something like %2d. You'll need to play with it a little to make them allign.

easter cards

Void main(){int k=15;if(k==15){printf("%d%d%d"... output?

c program


so i want result with explaination

Void main(){int k=15;if(k==15){printf("%d%d%d"... output?
You will get syntax error. You have no closing braces. The program is incomplete.
Reply:Incomplete program
Reply:Its statements mising like expression.and getch.for help contak me at y!


mesanger.
Reply:there is no output for this program..


the main part is missing in the program ..


which value ur displaying ? ??


printf("%d%d%d"


this line has no meaning . . .


How come my C++ codes work in Dev and not in Microsoft Visual express?

theres nothing wrong cuz it works in dev





here it is


#include %26lt;stdio.h%26gt;


#include %26lt;conio.h%26gt;





main()


{


int passes = 0, failures = 0, student = 1, result;





/* process 10 students; counter-controllede loop*/


while (student %26lt;= 10) {


printf("Enter result (1=pass,2=fail): ");


scanf("%d", %26amp;result);





if (result == 1)


passes = passes + 1;


else


failures = failures + 1;





student = student + 1;


}


printf("Passed %d\n", passes);


printf("Failed %d\n", failures);





if (passes %26gt; 8)


printf("Raise tuition\n");


else


printf("you have dumbass in your school\n");





getch();


return 0;


}

How come my C++ codes work in Dev and not in Microsoft Visual express?
it could have some syntax errors that are only readable in Visual express... try to code it in a different way and try again
Reply:Hm, looks a lot more like C code than C++ code. You may want to consider using %26lt;iostream%26gt; and cin/cout for input/output, as Visual Express is for C++, not C. Your errors are probably cause by your un-C++-ness





main() should be int main().


Not really an error, but you should use the ++ operator, ie


foo++; not


foo = foo + 1;


cout %26lt;%26lt; "foo"; not


printf("foo");


cin.get(); not


getch();


And it is considerably easier to use // for line comments rather than /* */
Reply:Did your teacher tell you that it had to compile in Microsoft Visual Express? Different compilers pick up different errors. I always progammed my C++ programs in Dev, and my teacher never had a problem compiling them.





One hint, though. You've programmed it so that anything other than a 1 is a fail. This means that numbers such as 3,4,5,0,etc, are all considered to be fails instead of incorrect input. I don't know how strict your teacher is, but this could be considered to be an error.


C programming?

i need to create a function that accepts 3 parameters. (array of int, size of the array, a value to search). if the 3rd parameter is found in the array, the function will return the location or index. otherwise, it returns -1.





i created this code.. but i think there's something wrong. anyone can help?





#include%26lt;stdio.h%26gt;





#define MAX 10





typedef int arrInt[MAX];





int searchFunction(arrInt a, int MAX, int nNum)


{


int j=0, nfound=0;


if(MAX!=0)


{


for(j=0;j%26lt;max;j++)


{


if(a[j]==nNum)


nfound=j;


}


if(nfound==0)


printf("Not Found!");


}


else


printf("No Array!");


return nfound;


}





main()


{


arrInt a[MAX];


int i, nNum, nValues, nSearch;








for(i=0,i%26lt;MAX;i++)


{


printf("Enter a number:");


scanf("%d",%26amp;nValues);


a[i]=nValues;


}





printf("What number do you want to search?");


scanf("%d",%26amp;nNum);





nSearch=searchFunction(a,MAX,nNum);


}

C programming?
First mistake I can see:





int searchFunction(arrInt a, int MAX, int nNum)





In this function, the first parameter is typed as "arrInt". There is no such data type in C. An array is really just a pointer to an integer, so your definition should look something like this:





int searchFunction(int *a, int MAX, int nNum)


{


}





As for the contents of the function, here are other mistakes...





for(j=0;j%26lt;max;j++)





There is no variable called "max", the one you defined earlier is called "MAX".





This last part is horrible:





if(nfound==0)


printf("Not Found!");


}


else


printf("No Array!");


return nfound;


}





You don't use an opening bracket on the first if statement or the else statement. If you are going to use closing brackets, you NEED opening brackets. Also, if those brackets meant to close the if and else, then there are two other parts of your function that are not closed: one is the function itself, and the other is the very first if statement in the function.





On the other hand, if you didn't mean to close the if and else with brackets, then then these lines:





if(nfound==0)


printf("Not Found!");





Belong OUTSIDE the bracket that comes after it. Your code, running the way it is, will keep printing "Not Found!" on the screen over and over regardless of whether the integer is found or not, since the program is still searching. The only way it would not print that message is if the very first number in the array was the one you were searching for.





Also, if the above code had worked correctly, it would return 0 if the integer was not found. This is not what the assignment asked... it's supposed to return -1.
Reply:"arrInt a" is wrong, it should be "int a[]". Also, one of your function arguments is MAX. Why are you overriding the constant that you already defined? Instead of using MAX each time you call the function, remove that parameter altogether and just access MAX normally. It will then be treated as the global (constant) variable that it is. if the variable is called "MAX", then you must use it as "MAX" each and every time, and not call it as "max" or "Max". After you fix that, I will look over it again if I get the chance.
Reply:I ll first point ur mistakes,


1. you have opened an if loop but not closed


to check forMAX!=0


2. You have assigned MAX as 10


but why do u want to check for MAX!=0, its logically wrong


3. U r returning some value to main() and


also u r printing whether u found or


not in the funtion itself. So wat is the use of


returning values if u r printing there itself.


4. u r checking whether nfound==0,


but consider this logic if the


value to be find itself is zero, then ur logic goes wrong.


5. I think u dint specify the typedef properly. Sorry i am not


sure about that.





Here is the soln:-


u get the value of array normally, and declare as normal int array.


function fn_name(parameters)


{


for(i=0;i%26lt;MAX;i++)


{


if(arr[i]==searchElement)


{


printf("found");


return i;


}


}


return -1;


}








very simple logic, if u found u ll return index, otherwise after the loops get over, it ll automatically return -1. So u can check in the main function and print the message accordingly.


Programming Database Program in Dev C++?

#include %26lt;stdio.h%26gt;





void fileChecker (char filename[20]);





char choice, menu, restart, filename[20], option, buffer;


int i, j, n, m, cnt = 0, flag;


FILE *fp;





struct record{


char lastName[20];


char firstName[20];


char cacNum[10];


} , tmp;





void main(int argc, char *argv[])


{


clrscr();


printf("Welcome to the Student Database!");


printf("\n\nPlease enter the following information:");


n = 0;


do{


printf("\n\nLastname: ");


printf("Firstname: ");


gets(student[n].firstname);


printf("CAC Number: ");


do{


printf("\nDo you wish to add another entry? (y/n) ");


choice = tolower(());


if(choice) == 'y')


{


n++;


}


}

Programming Database Program in Dev C++?
Oracletutorials.info is your gateway to the best


sites on the Internet for Oracle tutorials!


http://oracletutorials.info/
Reply:I HAVE MADE SOME COMMENTS BELOW...





void fileChecker (char filename[20]);





char choice, menu, restart, filename[20], option, buffer;


int i, j, n, m, cnt = 0, flag;


FILE *fp;





struct record{


char lastName[20];


char firstName[20];


char cacNum[10];


} , tmp;





void main(int argc, char *argv[])


{


clrscr();


printf("Welcome to the Student Database!");


printf("\n\nPlease enter the following information:");


n = 0;


do


{


printf("\n\nLastname: ");


printf("Firstname: ");


gets(student[n].firstname); YOU DECALRE TMP FOR THE STUCT, ARE YOU USING IT?


WHAT ABOUT LAST NAME?? GET IT??


printf("CAC Number: "); WHAT ABOUT CAC, GET IT??


do


{


printf("\nDo you wish to add another entry? (y/n) ");


choice = tolower(());


if(choice) == 'y')


{


n++;


}


}


}


while(choice != 'n');


n++; IF ITS NOT == THEN N++?? AGAIN





if(argc %26gt; 1)





{


( WHY IS THERE A PARENS HERE?


filename, argv[1];


fileChecker(filename);


}


else


{


printf(\n\nYou have not provided the Record Filename...");


retrieverFilename();


}


OKAY......FIRST YOU HAVE TO GO THROUGH THIS AND MAKE SURE ALL THE BRACES MATCH, COMMENT THEM,


ITS WAY TO HARD TO READ AND UNDERSTAND.


MAKE SURE YOU ARE GETTING THE INFO FROM THE USER AND PUTTING IT INSIDE YOUR ARRAYS,


REFORMAT THIS THING SO YOU CAN READ IT EASIER....THERE ARE MANY BRACES WHERE THERE SHOULDN'T BE AND EXTRA PARENS AND EXTRA BRACES..














fcloseall();


printf("\nSaving Completed!");


printf("\nThank You!");


do


{


print("\n\nDo you wish to restart the program? (y/n) ");


restart = (getche());


}


}








else


{


printf("\nGoodbye!");


exit(1);


}


}


/*************************************...


void retrieverFilename()


{


printf('\n\nEnter the Record Filename: ");


gets(filename);


fileChecker(filename);


}


/*************************************...


void fileChecker (char filename[20])


{


if((fp = fopen(filename, "r")) == NULL)


{


printf("\nDo you wish to \n(a) enter filename, \n(b)create a new file, or \n(c)exit the program\n? (a/b/c) ");


option = tolower(getche());


if(option == 'a')


{


retrieverFilename();


}


else if(option == 'b')


{


printf("\nCreating a New Record File...");


fp = fopen(filename, "w+t");


sorter();


storer();


}


else if(option == 'c')


{


printf("Goodbye!");


exit(1);


}


}


while(option != 'a' %26amp;%26amp; option != 'b' %26amp;%26amp; option != 'c');


}


else


{


printf("\n\nRecord File already exists!");


do


{


printf("\nDo you wish to


menu = tolower(getche());


}


while(menu != 'a' %26amp;%26amp; menu != 'b' %26amp;%26amp; menu != 'c' %26amp;%26amp; menu != 'd');








fclose(fp);


n = m;





fp = fopen(t");


storer();


}


else if(menu == 'c)


{


retrieverFilename();


}


else


{


printf("\nGoodbye!");


exit(1);


}


}


}

brenda song

It's about C program... please help.?

#include%26lt;stdio.h%26gt;


void pw(long,char[]);


char *one[]={" "," one"," two"," three"," four"," five"," six"," seven"," eight"," Nine"," ten"," eleven"," twelve"," thirteen"," fourteen"," fifteen"," sixteen"," seventeen"," eighteen"," nineteen"};


char *ten[]={" "," "," twenty"," thirty"," forty"," fifty"," sixty"," seventy"," eighty"," ninety"};





void main()


{


long n;


clrscr();


printf("Enter the no: ");


scanf("%9ld",%26amp;n);


if(n%26lt;=0)


printf("Enter numbers greater than 0");


else


{


pw(((n/1000)%100),"thousand");


pw(((n/100)%10),"hundred");


pw((n%100)," ");


}


getch();


}





void pw(long n,char ch[])


{


(n%26gt;19)?printf("%s %s ",ten[n/10],one[n%10]):printf("%s ",one[n]);


if(n)printf("%s ",ch);


}


==========


Output is:


Enter the no.: 25


twenty five


=========


can someone explain the code:


pw(((n/1000)%100),"thousand");


pw(((n/100)%10),"hundred");


pw((n%100)," ");





--what's the use of that code? i mean the use of %100, /100, etc? thanks

It's about C program... please help.?
The % is modulus and the / is division.





If the input is 6543 for instance, then:


pw(((n/1000)%100),"thousand");


(1) 6543 / 1000 = 6


(2) 6 % 100 = 6


The first value passed to pw function is 6 for 6 thousand.





pw(((n/100)%10),"hundred");


(3) 6543 / 100 = 65


(4) 65 % 10 = 5


The first value is 5 for 5 hundred.





pw((n%100)," ");


(5) 6543 % 100 = 43


The first value is 43 for 43 (ones).





Now, a brief definition of modulus.


Modulus of a number is the remainder after dividing the number by another number. For example,





If you the first number is 198, and the you want to find the 10 modulo of 198, represented 198 % 10, you do the following procedure.





(10) get the input number (i) // 98


(11) get the modulo number (m) // 10


(12) divide (i) by (m) // 198 / 10, [edit] 98 if 198 / 100 ( 198 % 100) [/edit]


(13) if the number remaining is greater than m


(13.1) then goto (11)


(13.2) else the number remaining is the modulus // 8





Sorry about the two similar names, modulo number and modulus.
Reply:the three lines of code do the following:





-if the number is greater than 1000 it puts the suffix "thousand"


-if the number is greater than 100 it puts the suffix "hundred"


-if the number is greater than 1000 it just states the output of the function "pw"





-the function pw tests the numer and transforms it into text :)


-the modulo operator (%) returns the numer that is left after substracting the most multplid product of the other number (i am ambiguous); let me explain:


47%5=47-45=2


(i subsracted 45 becouse it is the biggest number that divides exactly to 5 and is smaller than 47)
Reply:% is the symbol for the modulus operator. The modulus of 2 numbers is the remainder of 1 number repeatedly subtracted from the other.





Eg. 8 mod 7 = 1


4 mod 1 = 0


33 mod 30 = 3





The code is trying to work out how many thousands, hundreds and tens are in a given number.


How do I right justify this asterisk pattern (C)?

I want to turn this...





**********


*********


********


*******


******


*****


****


***


**


*





into this...





**********


!*********


!!********


!!!*******


!!!!******


!!!!!*****


!!!!!!****


!!!!!!!***


!!!!!!!!**


!!!!!!!!!*





without using field with specifiers. I can only use for loops and one printf for asterisks (*) and one printf for space ( ). Here's my code. Thanks.





Code:





#include %26lt;stdio.h%26gt;





int main() {





int f, g;





for(f = 0; f %26lt; 10; f++)


{


for(g = f; g %26lt; 10; g++)


{


printf("*");


}


printf("\n");


}


return 0;


}





I was able to right justify this...





*


**


***


****


*****


******


*******


********


*********


**********





using this code...





while(h %26gt;= 0)


{


for(j = 0; j %26lt; h; j++)


{


printf(" ");


}


--h;


for(j = 0; j %26lt; i; j++)


{


printf("*");


}


++i;


printf("\n");


}

How do I right justify this asterisk pattern (C)?
Hmmm. So using printf() field modifiers are out, eh? Well, this becomes more math-ish, then.





int h=10, i=0;





while(h %26gt;= 0)


{


for(j = 0; j %26lt; i; j++)


printf(" ");





for(j = 0; j %26lt; h; j++)


printf("*");





i++;


h--;


printf("\n");


}
Reply:welcome. thanks for coming back and choosing an answer! Report It

Reply:google is your friend: http://www.space.unibe.ch/comp_doc/c_man...


C code question?

#include %26lt;stdio.h%26gt;


#include %26lt;stdlib.h%26gt;





int main ()


{


int i, n;


int *pointerData;





printf ("Enter number of items to be stored: ");


scanf ("%d", %26amp;i);


pointerData = (int*) calloc (i, sizeof(int));





if (pointerData==NULL)


exit (1);





for (n = 0; n %26lt; i; n++)


{


printf ("Enter number #%d: ", n);


scanf ("%d", %26amp;pointerData[ n ]);


}


printf ("You have entered: ");





for (n = 0; n %26lt; i; n++)


printf ("%d ", pointerData[ n ]);


free (pointerData);


system("pause");


return 0;


}





can somebody tell me when does the first if statement will occur?


I know that when *pointerData is NULL. But what would the user enter so that pointerData will become NULL.





thanks

C code question?
You might also do like this so you can get a visual clue as to what's going on:





if (pointerData==NULL)


{


printf("Memory allocation failed! Exiting program...\n");


exit (1);


}





Otherwise, I'd say this code is fairly well written. Another poster had an issue with your cast of calloc's (void *) of allocated memory to an (int *). IMO, all this does is silence a compiler warning, and shouldn't affect performance whatsoever. ANSI experts and purists will disagree--and probably for good reason--because someday, in some instance, it could bite you, yes. But in many years of programming experience, I haven't run into that instance yet. Opinion mode, "off". And good luck.





Oh! And to answer your question, "when does the first if statement will occur?" ... almost immediately after you enter a value at the prompt:





printf ("Enter number of items to be stored: ");


scanf ("%d", %26amp;i);





The code execution progresses top down from main(), and there are no loops or anything to significantly delay execution to the first if(), (except the wait for the user to enter a value). A microsecond after the user enters a value, I'd say, is when the first if() gets hit...





I see one more question, "But what would the user enter so that pointerData will become NULL"





Answer: any number that is too large for calloc() to be able to allocate memory for that many integers.





sizeof(int) is variable depending on implementation, but generally 2 to 4 bytes. Now, we're allocating n * sizeof(int), so number of bytes of memory requested could be 2 to 4 times greater than n...that's important.





But certainly, and generally, any value of n less than 1,000 should give no problem...unless you have a hundred other applications running, or something equally bizarre.





////////////////////EDIT//////////


Thumbs up for you, CatNip! Poster wasn't asking when if() executes, but when it's true.





Now, see? I should have been able to translate that question.... :-) Kudos...
Reply:if there isn't enough memory for the calloc() to allocate the amount of space requested, then it will return a null pointer.
Reply:pointerData is set by the calloc() call. If calloc fails, because, for instance, the computer is out of free memory, then pointerData will be NULL.





You should ALWAYS ALWAYS ALWAYS test the results of calloc or malloc for success.





Also, calloc and malloc's result should NOT be cast like this.
Reply:The 1st if statement will be true if one of the following happens:





1. The calloc fails. See the errno for the error value.


2. If either input parameter into calloc is 0, then it may return a Null or it may not. It depends on the implementation, in which case the 1st If statement may not be true.


Need help with c-programming; strsr and other?

Write a function that takes as input a string containing HTML source code and returns both the # of images referenced in the code and the total screen area (in square pixels) occupied by the images


The function MUST have the following declarationint estImageContent(char *pacHTML, long int *pliArea);








1. Prompt the user for an input filename


2. Open the file, read its contents into a string (up to 20000 bytes), close file


3. Call estImageContent()


4. Print the following to the screen:


1. Input filename


2. Estimated # of images


3. Estimated total screen area in square pixels


5. Loop back to prompt





this is what i have so far


/* the first thing i did was uppercase*/





#include %26lt;stdio.h%26gt;


#include %26lt;string.h%26gt;


#include %26lt;ctype.h%26gt;








void fileToString(char filename[], char theString[]);


char *upperCaseTheString(char *pc);





int main()


{


char filename[] = "p6in1.txt";


char theString[20000] = "";





fileToString(filename, theString);


upperCaseTheString(theString);





printf("%s", theString);





return (0);


}








void fileToString(char filename[], char theString[]) {


FILE *fp;


char buf[BUFSIZ+1];





fp = fopen(filename, "r");





while (fgets(buf, BUFSIZ, fp) != NULL) {


strcat(theString, buf);


}





fclose(fp);





}








char *upperCaseTheString(char *pc) {


char *pcReturn = pc;





while (*pc != '\0') {


*pc = toupper(*pc);


pc++;


}





return pcReturn;


}


fp=fopen("p6in.txt","r");





if(fp==NULL)


{


printf("\n\t\tSORRY......\n\t\t CANNOT OPEN FILE\n");


return 0;


}





printf("\n\t\tFILE data.txt FOUND!\n");


printf("\n\nSearch what string?\t");


gets(str1);





while ((fgets( str2, 100, fp )) != NULL) //not the end of file


{


if (strcmp(str1, str2)


iCount++;











}


printf("\n%d OCCURRENCES OF STRING %s FOUND", iCount ,str1);








}

Need help with c-programming; strsr and other?
Here is a link with info about strstr:


http://www.cppreference.com/stdstring/st...
Reply:I don't know

bouquet

Problem with Doubly Linked Lists in C ?????

#include%26lt;stdio.h%26gt;


#include%26lt;malloc.h%26gt;





struct ListEntry


{


int number;


struct ListEntry *next;


struct ListEntry *previous;


};





void main()


{


int i=0;


struct ListEntry start, *node;





start.next ='\0';


start.previous= '\0';





node = %26amp;start;





printf("Address of the 1st node-%26gt;%d\n",node);





//TROUBLE STARTS


for(i=1; i%26lt;=10;i++)


{


node-%26gt;next = (struct ListEntry *)malloc(sizeof(struct ListEntry));


node-%26gt;next-%26gt;previous =node;


node = node-%26gt;next;


printf("Number-%26gt;%d node is %d\n",i,node);


node-%26gt;number = 50+i;


node-%26gt;next= '\0';


}


//TROUBLE ENDS


node = start.next;





do


{


printf("%d\n",node-%26gt;number);


printf("%d\n",node);


node = node-%26gt;next;


}while(node-%26gt;next);





printf("\n\nReversing\n\n");


do


{


printf("%d\n",node-%26gt;number);


printf("%d\n",node);


node = node-%26gt;previous;


}while(node-%26gt;previous);


}


I am having trouble understanding the for loop part !!

Problem with Doubly Linked Lists in C ?????
I believe the for loop will allocate 10 new nodes, setting the appropriate next and prior links, and assign the values 51 through 61 to the "number" variables within the nodes.





The printfs that follow should prove that out as they're responsible for dumping the contents of the list.
Reply:I believe this statement is illegal in C:





node = %26amp;start;


this could be done in C++, but it would be pointless in this context.


Help fixing a C program that I'm working on...?

for some reason i keep getting 1245036 as the new credit limit, no matter what I put in. Help?











#include %26lt;stdio.h%26gt;








int main()


{





int employee = 1;


int accountNumber;


int creditBefore;


int currentBalance;


int creditAfter;





while ( employee %26lt;= 3 ){








printf( "Enter account number: ");


scanf( "%d", %26amp;accountNumber );





printf( "Enter current balance: ");


scanf( "%d", %26amp;currentBalance );





printf( "Enter current credit limit: ");


scanf( "%d", %26amp;creditBefore );





creditAfter = creditBefore / 2;





printf( "Your new credit limit is %d\n", %26amp;creditAfter );





if ( creditAfter %26lt; currentBalance ){


printf( "Current balance exceeds new credit limit.\n" );


}


else{


printf( "Current balance does not exceed new credit limit.\n" );


}





}





return 0;





}

Help fixing a C program that I'm working on...?
It's been a while since I coded in C, but here goes:





In the printf("Your new credit limit is %d\n", %26amp;creditAfter); statement, the %26amp; indicates that you want to print the ADDRESS of creditAfter, not the value. Try it without the %26amp;.





I'm assuming that you're just playing around here. So the following two points aren't related to the problem that you're having but may yield unintended results.





If you divide an odd numbered integer by 2, the result will be a real number. By declaring creditAfter as int, any decimal portion will be truncated.





The condition for your while loop checks that employee is less than 3; however, employee is not being incremented within the loop. This will result in an infinite loop.
Reply:This line


printf( "Your new credit limit is %d\n", %26amp;creditAfter );


must be in the form


printf( "Your new credit limit is %d\n", creditAfter );





Here is the complete better program:





#include %26lt;stdio.h%26gt;





int main()


{


int employee = 1;


int accountNumber;


int creditBefore;


int currentBalance;


int creditAfter;





while ( employee %26lt;= 3 ){








printf( "\n\n\nEnter account number: ");


scanf( "%d", %26amp;accountNumber );





printf( "\nEnter current balance: ");


scanf( "%d", %26amp;currentBalance );





printf( "\nEnter current credit limit: ");


scanf( "%d", %26amp;creditBefore );





creditAfter = creditBefore / 2;





printf( "\nYour new credit limit is %d\n", creditAfter );





if ( creditAfter %26lt; currentBalance ){


printf( "\nCurrent balance exceeds new credit limit.\n" );


}


else{


printf( "\nCurrent balance does not exceed new credit limit.\n" );


}





}





return 0;





}
Reply:the statement scanf( "%d", ¤tBalance ); has to use %26amp;currentBalance, this particular variable is not declared, also the symbol should be %26amp; to mention the address


Simple Caculator in C, What am i doing wrong?

#include %26lt;stdio.h%26gt;


#include %26lt;stdlib.h%26gt;





void addMe(int x, int y);


void subtractMe(int x, int y);


void multiplyMe(int x, int y);


void divideMe(int x, int y);


int main()


{


int x, y, ans, i;


int choice;


ans=0;





printf("Enter the first number --%26gt;\n");


scanf("%d",%26amp;x);





printf("Enter the second number --%26gt;\n");


scanf("%d",%26amp;y);





addMe(x, y);


subtractMe(x, y);


multiplyMe(x, y);


divideMe(x, y);





system("PAUSE");


return 0;


}//endmain





void addMe(int x, int y)


{


ans = x+y;


printf("First plus Second = %d\n", ans);





}//add


void subtractMe(int x, int y)


{


ans = x-y;


printf("First minus Second = %d\n", ans);





}//subtract


void multiplyMe(int x, int y)


{


ans = x*y;


printf("First times Second = %d\n", ans);





}//multiply


void divideMe(int x, int y)


{


ans = x/y;


printf("First divided by second = %d\n", ans);





}//divide

Simple Caculator in C, What am i doing wrong?
if u define int ans before the declaration of funtions as a global variable it works without the need of defining them in each function.
Reply:So, perhaps I am mistaken, since it has been a long time since I have programmed much of anything in a main loop, but why are you "declaring" ans in the main loop instead of as a variable within each function? Additionally, your problem is that you don't declare 'ans', you just set it equal to 0, you need to declare it as an int.
Reply:you can also try this approach


instead of doing this





void multiplyMe(int x, int y)


{


ans = x*y;


printf("First times Second = %d\n", ans);


}//multiply





try this


void multiplyMe(int x, int y)


{


printf("First times Second = %d\n", x*y);


}//multiply
Reply:I'm not seeing anything that is jumping out at me as being wrong. I see a couple of things you will need to do.





One, you need so data checks. You need to make sure that the data that a user enters is really a number. If someone enters two letters it would cause your program to crash when it tried to add.





Second, when you subtract. Are you allowed to get an answer that is negative? If so how are you handling printing the number as a negative? If you can't have negitive numbers you need to check before you subtract that x is larger than y.





Third, when you divide you need to make sure that y isn't zero. This will also cause your program to crash since you cannot divide by zero.





The above are a few improvements on your program. If you are getting a specific error when compiling or running the program post those errors here so we can know where to look for a problem.
Reply:Can you post the error message?


Your code looks ok to me.


then again, its been 8 years since ive written a C program.


Can anyone who is expert in turbo c can correct my code here? thanks in advance:?

This is my code:


#include%26lt;stdio.h%26gt;


main()


{


int cas,cnt,ctr,x=1,y=2;


clrscr();


printf("Enter case number[1-4]:");


scanf("%d",%26amp;cas);


switch(cas)


{


case 1:


{ for(cnt=5;cnt%26gt;0;cnt--,x++,y++)


{for(ctr=cnt;ctr%26gt;0;ctr--)


gotoxy(x,y);printf("%d",ctr);


printf("\n");


}


break;


}





case 2:


{ for(cnt=1;cnt%26lt;=5;cnt++)


{for(ctr=cnt;ctr%26lt;=5;ctr++)


printf("%d",cnt);


printf("\n");


}


break;


}


case 3:


{ for(cnt=5;cnt%26gt;0 %26amp;%26amp; ctr%26gt;6;cnt--)


{for(ctr=1;ctr%26lt;=5;ctr++)


printf("%d",ctr);


printf("\n%d\n%d\n%d\n%d",ctr-4,ctr-...


}


break;


}


case 4:


{ for(cnt=1;cnt%26lt;=10;cnt++)


{for(ctr=1;ctr%26lt;=10;ctr++)


printf("%d\t",ctr*cnt);


printf("\n");


}


break;


}


}


getch();


}





--------------------------------


which must produce in case 1:


54321


4321


321


21


1








in case 2:


12345


1234


123


12


1








in case 3:


12345


2


3


4


5








in case 4:


10x10 multiplication table








thx in advance.... :-)

Can anyone who is expert in turbo c can correct my code here? thanks in advance:?
There's no need for a gotoxy in case1. In case 2 you're printing cnt, you should be printing ctr. I've rewritten case 3 to something simpler. Case 4 looks fine to me.





Enjoy.





switch(cas)


{


case 1:


for(cnt=5;cnt%26gt;0;cnt--)


{


for(ctr=cnt;ctr%26gt;0;ctr--)


printf("%d",ctr);


printf("\n");


}


break;





case 2:


{


for(cnt=1;cnt%26lt;=5;cnt++)


{


for(ctr=1;ctr%26lt;=6-cnt;ctr++)


printf("%d",ctr);


printf("\n");


}


}





case 3:


{


for(cnt=1;cnt%26lt;=5;cnt++)


{


printf("%d",cnt);


if (cnt==1)


for(ctr=2;ctr%26lt;=5;ctr++)


printf("%d",ctr);


printf("\n");


}


}


break;





case 4:


{


for(cnt=1;cnt%26lt;=10;cnt++)


{


for(ctr=1;ctr%26lt;=10;ctr++)


printf("%d\t",ctr*cnt);


printf("\n");


}


}


break;


}

yu gi oh cards

C program problem.......?

Write a program to do fraction arithmetic. A sample run follows:





Welcome to the Fraction Arithmetic program.


--------------------------------------...


Your problems with fractions can be solved here. Enter a


fraction arithemetic problem (Example 2/5 - 4/7). 1/2 + 1/4


The answer is 6/8.





Your program should handle the operations of addition, subtraction, multiplication


and division. The answer does not have to be in lowest terms for this version of the program.





Plan your program so that it is modular. Have the input done in one module,


the output done in a second module, and the calculation done in a third.


Put each module in a separate source code file. The function main() should reside in


its own module and be a driver program. If possible, try to write the


program without using any global variables.











Header file





enum ops {add,sub,mult,divide};





struct fraction


{


int num;


int den;


};





void problem8_7main();


void problem8_7input(struct fraction *first, struct fraction *second, enum ops *operation);


void problem8_7calc(struct fraction first, struct fraction second, enum ops operation,struct fraction *result);


void problem8_7output(struct fraction result);





Input module








#define _CRT_SECURE_NO_DEPRECATE





#include %26lt;stdio.h%26gt;


#include %26lt;stdlib.h%26gt;


#include %26lt;string.h%26gt;


#include "problem8_7.h"





void problem8_7input(struct fraction *first, struct fraction *second, enum ops *operation)


{


char Input[1024];





char *firsttoken = NULL;


char *opstoken = NULL;


char *secondtoken = NULL;


char *token = NULL;








printf("Welcome to the Fraction Arithmetic program.\n");


printf("------------------------------...


printf("Your problems with fractions can be solved here.\n");


printf("Enter a fraction arithmetic problem (Example 2/5 - 4/7)\n");





fgets(Input,1024,stdin);





firsttoken = strtok(Input," \n");


opstoken = strtok(NULL ," \n");


secondtoken = strtok(NULL ," \n");





token=strtok(firsttoken,"/");


first-%26gt;num=atoi(token);


token=strtok(NULL,"/");


first-%26gt;den=atoi(token);





token=strtok(secondtoken,"/");


second-%26gt;num=atoi(token);


token=strtok(NULL,"/");


second-%26gt;den=atoi(token);





switch(opstoken[0])


{


case '+':


*operation=add;


break;


case '-':


*operation=sub;


break;


case '*':


*operation=mult;


break;


case '/':


*operation=divide;


break;


}





}











Output module





#include "problem8_7.h"


#include %26lt;stdio.h%26gt;





void problem8_7output(struct fraction result)


{


printf("The result is %d/%d\n",result.num,result.den);





}

C program problem.......?
What is your question? If you are having a specific problem we can try to help you. I don't think you are going to get anyone to do this for you. Not for 10 points.


How do i end this c programming loop?....am i even using the right loop?

I compile and run...I enter test scores and the program keeps asking me to enter....it won;t stop...help.





it is the first while loop. i need it to end when the user hits Enter with no test score.


Purpose: Write a program that will find the lowest, highest, and average score for a set of test scores.


**************************************...


#include %26lt;math.h%26gt;


#include %26lt;stdio.h%26gt;


#include %26lt;stdlib.h%26gt;


#include %26lt;string.h%26gt;


main()


{


float score;


float average;


float x;


float max = 0;


float min = 1000; /*just in case there is extra credit*/


float total = 0;


float sum;


int i = 0;


char ac[BUFSIZ+1];





{





printf ("***********************************\n"...


printf ("*****Test Score Statisics *****\n");


printf ("***********************************\n"...





{





while ( score %26gt;= 0 ) {


printf("Please Enter test Score %d: ", i+1);


score = atoi(gets(ac));








if( score %26gt; max ) { /* Find Max Score*/


max = score;


}else{


if (score %26lt; min) { /* Find Min Score*/


min = score;


}


}


sum = score + sum; /* Find Sum Score*/


}





average = sum / i; /* Find Average Score*/





printf( "\n\nThe average score is %.1f\n", average);


printf( "%d Test Scores\n", i );


printf( "Maximun Test Score = %.1f\n", max);


printf( "Minimum Test Score = %.1f\n", min);





}


system("PAUSE");


return;


}}

How do i end this c programming loop?....am i even using the right loop?
// Replace this:


gets(ac);


if (ac[0] == 0) break;


score = atoi(ac);





// I'm Java/C#'er I have not touched C in years, fix it if wrong
Reply:you need to end the while loop after you finish printing your scores
Reply:the reson it dont exit is cuz your making sure score is always greter than zero. with the two if statments. you need to check after 'score = atoi(gets(ac));' if score is less than zero and break. and the while loop while ( score %26gt;= 0 ) should be while(true)
Reply:enter negative number


such as -1





But there are logical errors in the program.


Help. turbo c program!! ASAP!?

i have this program with me that will (supposedly) convert a rational number to a factorial. here is the code:


#include%26lt;stdio.h%26gt;





int quo,prod;


float point;


int multiply(int quotient){


int i=0,k=0;


k=fact2(quotient);


do{


prod=k*i;


i++;


}while(prod%26lt;=quotient);


prod=prod-(k);


i=i-2;


return(i);


}





int fact2(int quotient) {


int f = 1,i=0;


do {


i++;


f=f*i;


}while(f%26lt;=quotient);


f=f/(i--);


return(f);


}





int factorial(int quotient) {


int f = 1,i=0;


do {


i++;


f=f*i;


}while(f%26lt;=quotient);


i--;


return(i);


}





main() {


int a,b,f;


double ans,anss;


clrscr();


printf("Input rational: ");


scanf("%d/%d",%26amp;a,%26amp;b);


ans=(float)a/b;


printf("%d/%d = %f\n",a,b,ans);


if(ans%26gt;0)


printf("\n[0,[");


else{


printf("\n[1,[");


anss=ans*-2;


ans=ans+anss;


}


quo=ans;


point=ans-(quo+0.0);


loop(quo);


getch();


loop2(point);


getche();


}








int loop() {


int fact,mul;


while(fact%26gt;=1){


fact=factorial(quo);


mul=multiply(quo);


printf("%d,",mul);


quo=quo-prod; }


printf("],["); }

Help. turbo c program!! ASAP!?
int factorial2(float poinnt)


{


int f = 1,i=0;


do {


i++;


f=f*i;


}while(f%26lt;=point);


i--;


return(i); }





Right here, in factorial2(), the paramenter is "poinnt" -- which is never used in/by the function. The "point" used by the function is the global declared near the top of your code:





int quo,prod;


float point;





...bet that's why you're not getting expected results.





TIP1: if you turn up the warning level your compiler, then it should warn you about unused parameters like "poinnt", and it'll help you find these problems more rapidly/easily.





TIP2: this is why i always avoid use of globals whenever possible.


C programming language error message. "source file not compiled"?

here is the program i try to run. can u tell me what is wrong with it. please try first for your self . if it runs successfully then tell me.


its about to calculate average of three numbers.


/*------------------------------------...


/* this program will compute and display the averageof three numbers. */


#include %26lt;stdio.h%26gt;


void main ( void )


double n1, n2, n3; /* the three input numbers */


{


double average; /* the average of three nubers */


printf( "/n compute the average of three numbers/n" );


printf( "-------------------------------------/n... );


printf( "please input three numbers:" );


scanf( "%1g%1g%1g" %26amp;n1, %26amp;n2, %26amp;n3 ); /* read the numbers */


printf( "averaging %g, %g, %g," n1, n2, n3, ); /* echo inputs */





average = (n1+n2+n3) / 3.0; /* average is sum / 3. */


printf( "the average is %g/n/n", average ); /* print average */


}

C programming language error message. "source file not compiled"?
void main( void )


double n1, n2, n3;


{





should instead be


void main( void )


{


double n1, n2, n3 ;





Putting the variables before the opening brace was the old way of declaring function parameters.





BTW, If you use a strict compiler, it would complain about you saying main returns void. It really should return int..





If your compiler has an option to check for and report more warnings, I highly recommend it. That will catch a lot of things for you.

thank you cards

How do I write a printf statement for a unsigned integer 40000 left justified in a 15digit field w/8digits?

This is a question that deals with C programming.

How do I write a printf statement for a unsigned integer 40000 left justified in a 15digit field w/8digits?
printf("%-15u\n",40000);





provided I understood it correctly.


Help in deleting names in 2d array in C.?

# include%26lt;stdio.h%26gt;





char main ()


{


char name [24] ;


char list [6] [24];


char dname [24];


char temp;


printf("\n----------------------------...


printf("\nHello!, Please Enter Six Names of Your Choice");


printf("\nUse a space to separate each name\n");


printf("------------------------------...


for(int val = 0; val %26lt; 6; val++)


{


/* read the name */


scanf("%s", name);


/* copy the read name into the list of names */


for(int val2 = 0; val2 %26lt; 24; val2++)


list[val][val2] = name[val2];


}


printf("\n----------------------------...


printf("\n The names that you entered are:\n");


printf("------------------------------...


for (int i = 0 ; i %26lt; 6 ; i++ )


{


printf ( "%s\n", list[i] );


}


/*delete name*/


printf("\nEnter the name you want deleted\n");


for(int count=0;count%26lt;=5;count++)


{


scanf("%s",%26amp; dname);


if (dname != list[count])


{


printf("\n This name has been deleted: ""%s",dname);


}


}


return 0;


}

Help in deleting names in 2d array in C.?
The following code performs as you describe. I hope you find it useful.





Note: this code was compiled under a C++ compiler. You can use it in C with minor changes (like changing the comment syntax from dowble dash (//) to dash-star star-dash (/* */)).





//------------------------------------...





#include %26lt;stdio.h%26gt;


#include %26lt;string.h%26gt;





//------------------------------------...





#define MAX_NAMES6





char sName[MAX_NAMES][32];





//------------------------------------...





void PrintNames()


{


int i;





/* deleted names are treated as empty strings; the output code will ignore the empty strings thus showing as they were deleted */





printf("\nNames:\n");


for (i = 0; i %26lt; MAX_NAMES; i++)


if (sName[i][0] != '\0')


printf("%s\n", sName[i]);





printf("\n");


}





//------------------------------------...





int main()


{


char sTmpName[32];


int i;





// read the names


printf("Please, enter %d names.\n", MAX_NAMES);


for (i = 0; i %26lt; MAX_NAMES; i++)


{


printf("Enter name %d: ", i + 1);


scanf("%s", sName[i]);


} // end for





// print the list of names


PrintNames();





printf("Enter a name to delete: ");


scanf("%s", sTmpName);


i = 0;


while (i %26lt; MAX_NAMES %26amp;%26amp; strcmp(sTmpName, sName[i]) != 0)


i++;





if (i %26lt; MAX_NAMES)


{


// Name found





/* deleted names are treated as empty strings; so make this string empty (empty strings are diferent from NULL strings: empty strings are "", while NULL strings are those that point to no char array) */


sName[i][0] = '\0';


} // end if


else


printf("\nName \"%s\" NOT found\n", sTmpName);





// print the list of names


PrintNames();





return 0;


}


//------------------------------------...
Reply:Hi,


in the /* delete name*/ part of ur programme.


U have put scanf() in for(;;) loop. Scanf() should be just after the statement:


printf("\nEnter the name you want deleted\n");


then comes ur if() condition, it should check


if (dname == list[count])


then list[count]=" "; i.e., put a null string in place of the name to be deleted.


Then simply print ur array.


for checking string u could use


strcmp(dname,list[count]); function. It is in string.h header file. so include it #include%26lt;string.h%26gt;


if both the strings are equal it will return 0.





if (!strcmp(dname,list[count])


list[count]=" ";


i.e., put a null string in place of
Reply:Two things:





1. You're not actually deleting the entry from your array.





2. In C, use strcmp(dname, list[count]) for comparing strings. The "==" and "!=" operators don't work on strings (or at least not in the way you'd expect)





Several other things:


1. You can replace for(int val2 = 0; ...) list[val][val2] = name[val2] with:





strcpy( list[val], name );





Strcpy does that work for you.





2. You have the scanf() INSIDE your 0..4 loop so the user will have the enter a name 5 times. Put it outside the loop.


Can anyone help me to correct this turbo C program? thankyou in advance.?

this is my code:


#include%26lt;stdio.h%26gt;


main()


{


int cas,cnt,ctr,x=1,y=2;


clrscr();


printf("Enter case number[1-4]:");


scanf("%d",%26amp;cas);


switch(cas)


{


case 1:


for(cnt=5;cnt%26gt;0;cnt--,x++,y++)


{


for(ctr=cnt;ctr%26gt;0;ctr--)


gotoxy(x,y);


printf("%d",ctr);


printf("\n");


}


break;





case 2:


{


for(cnt=1;cnt%26lt;=5;cnt++)


{


for(ctr=1;ctr%26lt;=6-cnt;ctr++)


printf("%d",ctr);


printf("\n");


}break;


}





case 3:


{


for(cnt=1;cnt%26lt;=5;cnt++)


{


printf("%d",cnt);


if (cnt==1)


for(ctr=2;ctr%26lt;=5;ctr++)


printf("%d",ctr);


printf("\n");


}break;


}








case 4:


{


for(cnt=1;cnt%26lt;=10;cnt++)


{


for(ctr=1;ctr%26lt;=10;ctr++)


printf("%d\t",ctr*cnt);


printf("\n");


}


}


break;


}


getch();


}








and my problem is in the case 1:


which must produce:


54321


4321


321


21


1





but it produces:


54321


4321


321


21


1








thank you in advance.

Can anyone help me to correct this turbo C program? thankyou in advance.?
Well, you could do it with a case structure as you have, but what happens if you need to change it to 10 digits? The program grows twice as large.





I'm not sure why the case structure is being used. You can do this with a single for loop





cas has the value that they entered. So you need one outer loop to control the number of lines being printed, one inner loop to print spaces, and another inner loop to print the numbers as follows:





for (y=cas; y%26gt;0; y--) {


for (spaces=cas-y; spaces%26gt;0; spaces--) {


printf(" ");


}


for (x=y; x%26gt;0; x--) {


printf("%d",x);


}


printf("\n");


}


Why the output of printf("%d %d",a,*a) is 1 0 ?

when *a=1 and integer in c programing..

Why the output of printf("%d %d",a,*a) is 1 0 ?
make sure 'a' is defined as a pointer to another variable you've declared. like:





int b = 1;


int* a = %26amp;b;





Otherwise, if you simply declare


int* a;


*a = 1;





..then you have reserved memory for an address, but not for the contents. 'a' is pointing to a pseudo-random place in memory.





Secondly, printf() of 'a' should return the address you've reserved. printf() of '*a' should return the 1 as you're expecting. The most likely reason you're not seeing this is because 'a' is set to (1) - which means it is not a valid pointer. This can be caused by some compilers in a DEBUG build when a variable goes out of scope. As in:





int* a;


{


int b = 1;


a = %26amp;b;


}


// 'b' is now out of scope - some compilers will change memory to indicate this during a debug build. *a is now (0) !





Hope that helps.
Reply:could you more explain for me?Thank you Report It

Reply:it is wrong output ,


your output should be


value of 'a' and , value at 'a'


ie. (some memory address) , 1





recheck your code

potential breakup song

Why the output of printf("%d %d",a,*a) is 1 0 ?

when a=1 and integer in c programing..

Why the output of printf("%d %d",a,*a) is 1 0 ?
because a is a integer with value 1 and *a is a integer pointer which by default is initailised to 0


HELP!! Turbo C problem ..?

here is the program i made for our homework. supposedly it should be able to allow an integer and tell wether it is an odd or an even.. but i dont know where did i go wrong. please help me.





main()


{


/*Variable Declaration*/


int I;


int ODD, EVEN;


clrscr();


printf("Odd/Even Program\n");


printf("____________________\n");


printf("Enter an integer:"); scanf("%d",%26amp;I);


if(I%3)


{


EVEN=I;


printf("%d is an even integer",EVEN);


}


if (I%2)


{


ODD=I;


printf("%d is an odd integer",ODD);


}


printf("__________________\n");


printf("Press any key to exit....");


getch();


}

HELP!! Turbo C problem ..?
The problem with your code is there are many integers which are divisible both by 2 %26amp; 3. For eg., if you give input as 6 to your code both the if loops will be skipped and no answer will be displayed. Jus change your code as:


if (I%2)


{


ODD=I;


printf("%d is an odd integer",ODD);


}


else


printf("%d is an odd integer",EVEN);
Reply:Just like the prev person stated the only thing it's opposite





if ( i%2 )


{


printf("%d is an even integer",%26amp;i);


}


else


{


printf("%d is an odd integer",%26amp;i);


}


C-Programming question, help plz!?

I would like to write a program that would ask me do i like pears peaches and apples. And if i say yes for all 3 questions it should say that we accept you and if one of those is no then youre not accepted, here is the code!!!!





#include %26lt;stdio.h%26gt; // needed printf()


#include %26lt;conio.h%26gt; // needed for getch()


#include %26lt;string.h%26gt; // needed for strcmpi()











void main(void)


{


char answer1[30],answer2[30],answer3[30];


printf("Do you like pears?\n");


scanf("%s",%26amp;answer1);


printf("Do you like peaches?\n");


scanf("%s",%26amp;answer2);


printf("Do you like apples?\n");


scanf("%s",%26amp;answer3);


if (strcmp(answer1,"yes")==0)


if (strcmp(answer2,"yes")==0)


if (strcmp(answer3,"yes")==0)


printf("You are just what i need!\n");


else printf("Sorry you do not apply!!\n);








getch();





}





plz help me!

C-Programming question, help plz!?
#include %26lt;stdio.h%26gt; // needed printf()





#define MAX_Q 5


#define MAX_A 30








int main(void){ // void main() is wrong.


// Don't Ever do that.


int c; // For Later


// Array of Strings


char answer[MAX_Q][MAX_A];


printf("Do you like pears?\n");


scanf("%s",%26amp;answer[0]);


printf("Do you like peaches?\n");


scanf("%s",%26amp;answer[1]);


printf("Do you like apples?\n");


scanf("%s",%26amp;answer[2]);


if( (answer[0][0]=='y'||


answer[0][0]=='Y') %26amp;%26amp;


(answer[1][0]=='y'||


answer[1][0]=='Y') %26amp;%26amp;


(answer[2][0]=='y'||


answer[2][0]=='Y') )


printf("You're just what I need!\n");


// If it starts with 'y' or 'Y', it's probably "Yes"


else


printf("Sorry you do not apply!!\n");


// You were missing a another quote earlier.








while(1) // Press x and then enter to quit


if((c=getchar())=='x')


return 0;





return 0;


}
Reply:try the %26amp;%26amp; inside the if clause





if ((strcmp(answer1,"yes")==0) %26amp;%26amp;


(strcmp(answer2,"yes")==0) %26amp;%26amp;


(strcmp(answer3,"yes")==0) %26amp;%26amp;)


printf("You are just what i need!\n");


else


printf("Sorry you do not apply!!\n);
Reply:Your else statement is not doing what you intend. It will only execute if you pass the first two ifs, then fail the third if.





Either use %26amp;%26amp;, as another answer suggested, or use brackets in all of your if statements so you can see the flaw in your code flow (always a good idea anyway).


Please output this program printf("\x30\48");?

c++ statment

Please output this program printf("\x30\48");?
It printed this for me 0♦8





Hope this Helps.


Good Luck!!!
Reply:Its going to print \x30\48 on the screen. what exactly are you trying to program?

love song

Can anyone add a loop uising c?

# include %26lt;stdio.h%26gt;


/*beginning of program*/


main()





{


/* enter the variables that will be used*/


int account,beginning,total,allowed,credit,a...


/*accout number will be inputted*/


printf("Enter Account Number:\n\n");


/*recieves the number inputed from the keyboard*/


scanf("%d", %26amp; account);


/* beginning balance is inputted*/


printf("Enter beginnig balance of the month\n\n$");


/*recieves the number inputed from the keyboard*/


scanf("%d", %26amp; beginning);


/* total charged is asked*/


printf("Enter total charges \n\n$");


/*recieves the number inputed from the keyboard*/


scanf("%d",%26amp; total);


/* ask for the total credit of the card*/


printf("Enter total credits\n\n$");


/*recieves the number inputed from the keyboard*/


scanf("%d",%26amp; allowed);


/* ask for the credit limit of the card*/


printf("Enter credit limit to customer\n\n$");


/*recieves the number inputed from the keyboard*/


scanf("%d", %26amp; credit);


/*adds the beginning balance and credit allowed-credit limit*/


answer= beginning+allowed-credit;


/*prints the remainder from the credit limit*/


printf("Your balance is $%d\n\n", answer);


/*prints account number*/


printf("Account %d\n\n",account);


/*prints allowed credit*/


printf("Allowed is $%d\n\n",allowed);


/*prints the credit remaining*/


printf("Credit is $%d\n\n",credit);





/*shows ifyou have succeed or credit limit or not*/


if(answer %26gt; allowed)


/*prints the answere to the equatio above*/


printf("Credit limit exceeded. sorry sir/madam i'll have to cut your card ha-ha\n\n");


/*end of program*/





}

Can anyone add a loop uising c?
before ur first printf(); statement write


for(int i = 0; i %26lt;= 5; i++)


{


//all ur statements;


}


and include all the statements till ur last printf();


this will repeat all the steps i.e loop 5 times.
Reply:Homework question? There's a different section for that. You're asking someone to do a lot of work for you!





Your question is not clear or concise, you'll never get to be a programmer if you don't learn to spell right, and you need to learn how to work out problems like this without someone giving you the answer. Try opening the textbook, study your class notes a little, and see what happens!





P.S. This is very basic programming. If you don't get this, maybe you're in the wrong major?


C++ error message?

I keep getting an error in my program,


syntax error before '=' token





the line that it is referring to is,


if (number = =0) printf ("The bianary code for 0 is 00\n");





the whole program is here,


#include %26lt;stdio.h%26gt;


#include "genlib.h"


#include "simpio.h"





main()


{


int number;


number=GetInteger();


if (number = =0) printf ("The bianary code for 0 is 00\n");


else if (number = = 1) printf ("The bianary code for 1 is 01\n");


else if (number = = 2) printf ("The bianary code for 2 is 10\n");


else if (number = = 3) printf ("The bianary code for 3 is 11\n");


else if (number %26gt;3) printf ("The input you entered, %d, is out of range\n"number);


getchar();





}

C++ error message?
Do you have "= =" or "==" in those statements?





C++ (as well as C) expects to see "==" for an equality test
Reply:Try using a single = instead of a double = this might help- Good luck!
Reply:Well, I don't know what GetInteger() does...but whatever it returns the first if might not like.


Comment out your if and Print out the value of number first.


See what it is and if that GetInt function is working right
Reply:Your equality operators are wrong, its "==" instead of "= =" (no spaces. ignore the quotation marks in my example.


Why the output of printf("%u",***(&(*(&q)))) is 10?

when i=10 and *p=%26amp;i and **q=%26amp;p and all of them are integer in c programing..

Why the output of printf("%u",***(%26amp;(*(%26amp;q)))) is 10?
Is this some sort of weird homework question? Because if you did that while at work, someone needs to smack you.





Think of it this way: the *s cancel out the %26amp;s, and if you do that, you're left with **q, which = %26amp;p, et cetera.


Solve this c prog call by value & add. I compile this pgm i didn't get any error.but i get error when I run?

here is the program..(I get error -"undefined symbol"





#include%26lt;stdio.h%26gt;


void main()


{


int n1 = 25, n2 = 50;





printf(“\n Before call by Value : ”);


printf(“\n n1 = %d n2 = %d”,n1,n2);





val_swap( n1, n2 );


printf(“\n After call by value : ”);


printf(“\n n1 = %d n2 = %d”,n1,n2);





printf(“\n Before call by Address : ”);


printf(“\n n1 = %d n2 = %d”,n1,n2);


val_swap( %26amp;n1, %26amp;n2 );


printf(“\n After call by address : ”);


printf(“\n n1 = %d n2 = %d”,n1,n2);





}

Solve this c prog call by value %26amp; add. I compile this pgm i didn't get any error.but i get error when I run?
check this site


http://www.freewebs.com/cprogramm/
Reply:The code is o.k. Probably problem is either inside val_swap funciton or in the way you use it. If you give the code for that function I, possibly, will be able to tell you more.
Reply:the problem must be in the function val_swap...





i used devc++ to see check th code also had problems with the ". besides that the only problem is the val_swap func





val_swap( n1, n2 );

garden flowers

Is it possible that without using printf statement to print the output?

c and c++

Is it possible that without using printf statement to print the output?
Yes use the:





cout %26lt;%26lt; "i'm not using printf to write text!!!" %26lt;%26lt; endl;





the "endl" bit is for the program to jump to the next row ...
Reply:YES IT IS POSSIBLE TO PRINT OUTPUT WITHOUT USING PRINTF() FUNCTION. TO PRINT OUTPUT WE SHOULD USE THE ADRESS OF MONITOR OR DISPLAY UNIT


I'm trying to do a simple C program and I need to figure out how to check if a user input is a floating point?

I can't figure out why this code doesnt' work.


#include%26lt;stdio.h%26gt;


#include%26lt;stdlib.h%26gt;


#include%26lt;conio.h%26gt;





float salesTax(float input, float rate);





int main(){


float amount;


float i = .0725;


float j = .075;


float k = .0775;


printf( "Enter in the purchase amount please! (Amount Must Be Positive) " );


scanf( "%f", %26amp;amount );


while ( amount %26lt;= 0 ) {


printf ("ERROR: You have to enter in a positive digit. Try Again\n\n\n" );


printf("Press any key to continue. . . \n");


getch();


clrscr();


printf( "Enter in the purchase amount please! (Amount Must Be Positive) " );


scanf( "%f", %26amp;amount );}


clrscr();


printf("Your purchase price: $%d", amount);


printf("Del Mar Tax = " );


printf("%.2f\n\n", salesTax(amount,i));


printf("Encinitas Tax = ");


printf("%.2f\n\n", salesTax(amount,j));


printf("La Jolla Tax = ");


printf("%.2f\n\n\n\n", k);


printf("Press any key to continue. . . \n");


getch();


return 0;}





float salesTax (float input, float rate){


return input*rate;}

I'm trying to do a simple C program and I need to figure out how to check if a user input is a floating point?
You didn't say what happens, but there's two suspicious statements:





printf("Your purchase price: $%d", amount);





amount is a float so the format specifier should be %f not $d.





printf("%.2f\n\n\n\n", k);





This prints only the rate, not the tax amount. Should be salesTax(amount,k);





Other than that it probably works.

calling cards

C programming help?

Can someone please review my code? Its supposed to store 3 student's first name, last name and ID number into an array and then print them out, but I keep getting a segmentation fault after entering the 3rd students info.





#include %26lt;stdio.h%26gt;





struct student_record


{


int firstn;


int lastn;


int id;


};





int main()


{





int i, j;





struct student_record students[3];








for(i=0; i%26lt;=2; i++)


{


printf("Entry %i\n", i+1);


printf("First name\n");


scanf("%s", %26amp;students[i].firstn);


printf("Last name?\n");


scanf("%s", %26amp;students[i].lastn);


printf("ID?\n");


scanf("%s", %26amp;students[i].id);


}





for(j=0; j%26lt;=2; j++){


printf("Student %i\n", j+1);


printf("Name: %s %s\n", students[j].firstn, students[j].lastn);


printf("ID: %s\n", students[j].id);


}





return 0;


}

C programming help?
I think you might want to use %d instead of %s for integers...





For more tips, visit http://www.mycsharpcorner.com
Reply:I think you are missing a "," a period after :struct student_record
Reply:Probably not the reason but why are you defining three integers for what are really three char *?





On theme now, which compiler/OS are you in?
Reply:when your getting the ID's from the user you want to use %d if they are integers or %f if they are anything longer than an int. I bet using %s to get the ID's is causing it to store more information than an int can hold so thats whats throwing your error.
Reply:Have you covered strings yet in your programming class? Recall that a char is *one* character. Like 'a'. Or 'z'. So something like 'Michael' is *many* characters or a string. Clearly, char firstn is inappropriate, because you want a string.





Do some reading: http://www.cprogramming.com/tutorial/c/l...





So there's a few different things you can do. You can use a char* in your struct which will point to a C string. Or create an array like char firstn[50] and scanf into that array.


C++ (structures)what is the matter with the following program?

//stores and retrieves data for two secret asgents


#include%26lt;stdio.h%26gt;





void main ()


{





struct personnel {


char name [30];


int agnumb; int agent;


};





struct personnel agent1;


struct personnel agent2;


char numstr[81];





printf("\nagent 1.)\nEnter name:");


printf("Enter agent number (3 digits): ");


gets(numstr);


agent1.agnumb=atoi(numstr);


gets(agent2.name);


printf("Enter agent number (3 digits);");


gets(numstr);


agent2.agnumb=atoi(numstr);





printf("\nList of agents:\n);


printf(Agent number: %03d\n", agent1.agnumb);


printf("Name: %s\n", agent2.name);


printf(Agent number: %3d \n", agent2.agnumb);


}





please help correct the program, there after, from the same program, use arrays so that the structure can store and retrieve data on 20 agents.

C++ (structures)what is the matter with the following program?
struct personnel %26lt;------what's this, and why are some of your declarations in curly backets?


{


char name [30];


int agnumb; int agent;


};


Also, where are the scanf statements for input?


your best bet, as far as I know, is a 20 time for loop. Inside, the code to scan in all the data, and a counter to send it to the propper location in the array.





Hope that helped. Then again, I have a 5 month experience from school on C, lol. Good luck.


I need help completing this C code. Basically it asks user for input String and reverses it and changes cases.

#include %26lt;stdio.h%26gt;





char* strRev(char* line);


//your code here


char* str2Lower(char* line);





main(void){


//your code here


while(opt != 4){


printf("\n--------------------------...


printf("\nCST220 --- Assignment 2\n");


printf("Joe Smith XXX-YY-ZZZZ\n\n");


printf("Please choose the type operation\n");


printf("1. Reverse an string\n");


printf("2. Change an string to upper case\n");


printf("3. Change an string to lower case\n");


printf("4. End application (Exit)\n");


printf("Option: ");


scanf("%d", %26amp;opt);





if(opt != 4 %26amp;%26amp; (opt %26gt;= 1 %26amp;%26amp; opt %26lt;= 3)){


printf("\n\nPlease enter the string: ");


//your code here


if(opt == 1){


printf("\nThe reversed string is : %s", strRev(str));


}


else if(opt == 2){


printf("\nThe string in uppercase: %s", str2Upper(str));


}


else if(opt == 3){


printf("\nThe string in lowercase: %s", str2Lower(str));


}


}


}


}


char* strRev(char* line){


//your code here


return str2;


}





char* str2Upper(char* line){


//your code here


return str2;


}





char* str2Lower(char* line){


//your code here


return str2;


}

I need help completing this C code. Basically it asks user for input String and reverses it and changes cases.
#include %26lt;ctype.h%26gt;





char* strRev(char* line) {


char *str2, first;


str2 = line+strlen(line)-1;


while (str2%26gt;line) {


first = line;


*line = str2;


*str2 = first;


line++;


str2--;


}


return str2;


}





char* str2Upper(char* line) {


while( *line ) {


*line = toupper(*line);


line++;


}


return line;


}





char* str2Lower(char* line) {


while( *line ) {


*line = tolower(*line);


line++;


}


return line;


}


C program, whats the problem with this? pls check it out..?

#include %26lt;stdio.h%26gt;


main(void)


{


int i, j;


float price[10];





printf(" Please key in an initial price in RM: ");


scanf("%f", %26amp;price[0] );





printf(" \n\t\t\tMyZan Departmental Store\n ");


printf(" \t\t\t ");





for(j=1;j%26lt;=24;j++)


{


printf("-");


}


printf("\n\n");


printf("%30s%25s", "Price Before", "Price After");


printf("\n%28s%28s", "Discount", "20 % Discount");


printf("\n%26s%25s", "(RM)", "(RM)");





printf("\n");


for (i=0; i%26lt;=9; i++)


{


price[i+1] = price[i] *0.8;


printf( "\n%26.2f",price[i] );


printf( "\t%19.2f", price[i+1] );


price[i+1]=price[i]+10;


}





}

C program, whats the problem with this? pls check it out..?
Without knowing exactly what's going wrong, the project description seems to indicate that this line:





price[i+1]=price[i]+10;





should use price[i+1] as its source, rather than price[i].





The loop should also run while i%26lt;9, not %26lt;=.





Hope that helps.
Reply:%26gt; float price[10];


%26gt; for (i=0; i%26lt;=9; i++)


%26gt; price[i+1] = price[i] *0.8;





You can't write to price[10].





I don't fully understand why you're writing the discount price into the next entry in the array at all though, so I don't know how to recommend what to change.





edit: I'd suggest not storing either the "next" value or the discount value in an array. Conceptually much simpler, and you overwrite the % immediately anyway.

pokemon cards