NEW TO C++!!! ADDITION!! I am doing this for a school project!

I am doing a food store program, after the person inputs how many he likes each product, It'll multiply with the price, Now the problem is with the addition of the bought items.(USING TURBO C++)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

main(void)
{
 clrscr();
 int croissant,tamis,tamiswcheese,falafil,cocktail,pepsi,water;
 int c,t,tc,f,cock,p,w;
 int c1,t1,tc1,f1,cock1,p1,w1;
 int total;

 croissant=2;
 tamis=5;
 tamiswcheese=7;
 falafil=5;
 cocktail=5;
 pepsi=2;
 water=1;
 total=c1+t1+tc1+f1+cock1+p1+w1; // I THINK THIS HAS THE ERROR!!!

 textcolor(YELLOW);
 gotoxy(19,4);
 cprintf("We offer you:                 Price   How many    Cost ");

 textcolor(YELLOW);
 gotoxy(19,7);
 cprintf("1. Croissant                   2 SR       ");
 cscanf("%d",&c);
 gotoxy(69,7);
  c1=croissant*c;
 cprintf("%d SR",c1);
 getch();

 textcolor(YELLOW);
 gotoxy(19,9);
 cprintf("2. Tamis                       5 SR       ");
 cscanf("%d",&t);
 gotoxy(69,9);
  t1=tamis*t;
 cprintf("%d SR",t1);
 getch();


 textcolor(YELLOW);
 gotoxy(19,11);
 cprintf("3. Tamis w/ Cheese             7 SR       ");
 cscanf("%d",&tc);
 gotoxy(69,11);
  tc1=tamiswcheese*tc;
 cprintf("%d SR",tc1);
 getch();


 textcolor(YELLOW);
 gotoxy(19,13);
 cprintf("4. Falafil                     5 SR       ");
 cscanf("%d",&f);
 gotoxy(69,13);
  f1=falafil*f;
 cprintf("%d SR",f1);
 getch();


 textcolor(YELLOW);
 gotoxy(19,15);
 cprintf("5. Cocktail                    5 SR       ");
 cscanf("%d",&c);
 gotoxy(69,15);
  c1=cocktail*c;
 cprintf("%d SR",c1);
 getch();


 textcolor(YELLOW);
 gotoxy(19,17);
 cprintf("6. Softdrinks (Any)            2 SR       ");
 cscanf("%d",&p);
 gotoxy(69,17);
  p1=pepsi*p;
 cprintf("%d SR",p1);
 getch();

 textcolor(YELLOW);
 gotoxy(19,19);
 cprintf("7. Water                       1 SR       ");
 cscanf("%d",&w);
 gotoxy(69,19);
  w1=water*w;
 cprintf("%d SR",w1);
 getch();

 textcolor(YELLOW);
 gotoxy(60,21);
 cprintf("Total: %d SR", total);
 getch();


} 
 
1. Turbo C++ is deprecated
2. conio.h is deprecated (https://en.wikipedia.org/wiki/Conio.h )
3. Your code is C, not C++
4. main is missing its return type of int
Last edited on
tsk, it's what our prof's been teaching to us.are there many fixes should be done? can you point it out for me? sooo new to programming :)
I already pointed out the four main things to be fixed, but if your professor requires these things there's little help I can give. The problem with learning C++ is that there are plenty of bad books and lots of bad professors, and it is easy to get stuck being taught things which are just plain wrong.

Can you say specifically what you need help with?
(Sorry for bad english) my problem is, the program displays the wrong answer on the addition part(prolly adding numbers im not aware of) Inputted values should be added then the sum be displayed correctly. Im stuck with that. Sorry if im annoying.
On line 20, you are actually assigning to the value of total, not setting up a relationship. So, all of the variables you are using are not even initialized, so they contain junk garbage values. Move line 20 to after the variables are initialized.
done... but still it gives wrong answer xD
Post your modified code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

main(void)
{
 clrscr();
 int croissant,tamis,tamiswcheese,falafil,cocktail,pepsi,water;
 int c,t,tc,f,cock,p,w;
 int c1,t1,tc1,f1,cock1,p1,w1;
 int total;

 croissant=2;
 tamis=5;
 tamiswcheese=7;
 falafil=5;
 cocktail=5;
 pepsi=2;
 water=1;


 textcolor(YELLOW);
 gotoxy(19,4);
 cprintf("We offer you:                 Price   How many    Cost ");

 textcolor(YELLOW);
 gotoxy(19,7);
 cprintf("1. Croissant                   2 SR       ");
 cscanf("%d",&c);
 gotoxy(69,7);
  c1=croissant*c;
 cprintf("%d SR",c1);
 getch();

 textcolor(YELLOW);
 gotoxy(19,9);
 cprintf("2. Tamis                       5 SR       ");
 cscanf("%d",&t);
 gotoxy(69,9);
  t1=tamis*t;
 cprintf("%d SR",t1);
 getch();


 textcolor(YELLOW);
 gotoxy(19,11);
 cprintf("3. Tamis w/ Cheese             7 SR       ");
 cscanf("%d",&tc);
 gotoxy(69,11);
  tc1=tamiswcheese*tc;
 cprintf("%d SR",tc1);
 getch();


 textcolor(YELLOW);
 gotoxy(19,13);
 cprintf("4. Falafil                     5 SR       ");
 cscanf("%d",&f);
 gotoxy(69,13);
  f1=falafil*f;
 cprintf("%d SR",f1);
 getch();


 textcolor(YELLOW);
 gotoxy(19,15);
 cprintf("5. Cocktail                    5 SR       ");
 cscanf("%d",&c);
 gotoxy(69,15);
  c1=cocktail*c;
 cprintf("%d SR",c1);
 getch();


 textcolor(YELLOW);
 gotoxy(19,17);
 cprintf("6. Softdrinks (Any)            2 SR       ");
 cscanf("%d",&p);
 gotoxy(69,17);
  p1=pepsi*p;
 cprintf("%d SR",p1);
 getch();

 textcolor(YELLOW);
 gotoxy(19,19);
 cprintf("7. Water                       1 SR       ");
 cscanf("%d",&w);
 gotoxy(69,19);
  w1=water*w;
 cprintf("%d SR",w1);
 getch();

 total=c1+t1+tc1+f1+cock1+p1+w1;

 textcolor(YELLOW);
 gotoxy(60,21);
 cprintf("Total: %d SR", total);
 getch();


}

here it is...
Topic archived. No new replies allowed.