Can anyone help me.. I can't make this code work.
The third entry overwrites the second entry.. how can I make it go to the next line.
Bash |
THanks..
Bash |
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Danatas GerviRank #4,152 · 361 reputationPosted Aug 1, 2009, 11:58 PM EDT
:)
jhaysonn jhaysonn13 reputationPosted Aug 2, 2009, 1:27 AM EDT
actually on the first entry there's already an output for the third entry, when third entry is encoded, it overwrites the second entry.
did i miss something on my program?
Danatas GerviRank #4,152 · 361 reputationPosted Aug 2, 2009, 2:15 AM EDT
(I do not know, what is in gotoxy(...) function, and how it affects on global variables qtty1 ets.)
int _tmain(int argc, _TCHAR* argv[]) { printf("Details of the purchase..."); printf("\r\n"); printf("%s","erer"); printf("%f",6); printf("%d",6); printf("%f",6); printf("\r\n"); printf("%s","erer"); printf("%f",8); printf("%d",8); printf("%f",8); printf("\r\n"); printf("%s","erer"); printf("%f",9); printf("%d",9); printf("%f",9); printf("\r\n"); getchar(); return 0; }this is console output :
Details of the purchase...
erer0.00000060.000000
erer0.00000080.000000
erer0.00000090.000000
Print the output that you need - may be it help me to understand your problem.
:-)
jhaysonn jhaysonn13 reputationPosted Aug 2, 2009, 3:01 AM EDT
actually the situation is this: I am asked to create a program on C that will do the purchase, list and compute of all the products bought on me. With a max of ten items, then display all items bought before showing the total amount to be paid and the change.
here is my complete code..
my problem is: on the third entry, after encoding the data for the second entry there is already a display on the third entry, when i encode the data on the third it overwrites the previous data on the third. How can I eliminate an entry to appear before I encode a data?
thanks....
Danatas GerviRank #4,152 · 361 reputationPosted Aug 2, 2009, 3:32 AM EDT
I have no gotoxy() and clrscr() function - probably they are existing in additional dll for your devise...
So, try to use gotoxy() for setting the next line for output, and/or clear previos string by prining to same place an "space" string like printf(" ");
Sorry, that i cannot help you more - i have different programming enviroment (i mean - i cannot see the problem in runtime)...
:-(
jhaysonn jhaysonn13 reputationPosted Aug 2, 2009, 3:41 AM EDT
I am using the TurboC++IDE (as shown on it's window).
I can't really make it work... *sigh*
can somebody help me? appreciate so much.
thanks.
Danatas GerviRank #4,152 · 361 reputationPosted Aug 4, 2009, 8:14 AM EDT
It's me again.
I wanted to say, that your code was terrible. But it is not good to do so and do not explain, why.
So, your code was terrible. ;-)
Have a look, how it may be designed (use it as template):
#include "stdafx.h" #include"conio.h" #include"dos.h" struct ProductInfo { char Name[10]; int Qtty; float Prise; }; int ShowCurrentPurchaseDetails(ProductInfo onePurchase[]); int _tmain(int argc, _TCHAR* argv[]) { ProductInfo onePurchase[10] = {0,0,0,0,0,0,0,0,0,0}; cprintf("Welcome to D129 Store"); getch(); cprintf("\nYou're One-Stop Store.."); getch(); char ContinuePurchase = 'y'; int ii = 0; while (ContinuePurchase == 'y' && ii 0) { printf("\nName %s prise %f qtty %d",onePurchase[ii].Name, onePurchase[ii].Prise, onePurchase[ii].Qtty); sum += onePurchase[ii].Prise * onePurchase[ii].Qtty; } } printf("\ntotal sum now = "); printf("%f",sum); return 0; }you can use yours gotoxy() and clrscr() instead "\n" (new line)
Thanks for this C coding practice. It was so nostalgically for me.
:-)
jhaysonn jhaysonn13 reputationPosted Aug 4, 2009, 3:03 PM EDT
Thanks for that, but I find it hard to understand that source code, sorry just a beginner here.. hehe
I also don't get what is stdafx.h
thanks again.
Danatas GerviRank #4,152 · 361 reputationPosted Aug 5, 2009, 12:18 AM EDT
To use array of struct for grouping linked data - not Qtt1, Qtt2 ... Qtty10 .... Qtty13456. and ProdName500!
To use cicle (wile, for ...) instead spagetty-like code goto Qtyy1Calculate goto back....
To use fuction call - for every same algorithm parth.
You problem - this is not "output hides previos data" - the problem is that all algorithm is not developed.
Danatas GerviRank #4,152 · 361 reputationPosted Aug 5, 2009, 12:22 AM EDT
This is header file that needs to compile the code in my enviroment (VS2008)
you may use all your function with your header files. Remove it .
jhaysonn jhaysonn13 reputationPosted Aug 5, 2009, 4:14 AM EDT
Danatas GerviRank #4,152 · 361 reputationPosted Aug 5, 2009, 5:55 AM EDT
if ((argc < 2) ||
(sscanf(argv[1],"%d",&n) != 1) ||
(n < 1) || (n > 9)) {
printf("usage : %s
puts(" where 0 < n < 10");
return -1;
}
is command line argument parameters validation.
you can remove it - it is not affect on code - you can set this n haddcoded:
int n = 6; // for example
Danatas GerviRank #4,152 · 361 reputationPosted Aug 5, 2009, 6:08 AM EDT
str = calloc(n+1,sizeof(char));
- getting the memory in heap (not in stack)
for string (array of char) +1 byte more for 0 array terminator
this
for (i = 0, j = n; i < n; i++, j--)
{
str[i] = j + '0';
}
inserting to string (do not forget this is the array of chars) 654321
this
for (i = 1; i <= n; i++) {
printf("%s\n",str);
memset(str,' ',i);
}
two things - printing,
and modifying the string directly in memory - by inserting to char 1, char 2 ets the char ' ' (space)
free(str); // freeing the memory (no memory leakadge! :-) )
return 0;
This exaple seems optimal to you demend (if you want only output, and do not interesting to save this tabulated array.....
jhaysonn jhaysonn13 reputationPosted Aug 7, 2009, 8:30 PM EDT