problem with program

I am trying to do this program but i am getting many errors. If you understand please help me.
what i got so far:
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
#include <iostream>
#include<cstring>
using namespace std;

int main()
{
do
	//declare variables
	int number = 0;
	char choice1;
	char choice2;
	double 0 time;
	double 1 time;
	double 2 times;
	double 3 times;

	{
		cout << "\nDo you want to continue?   (y/n)? ";
		cin >> choice1 >> Choice2;
		if (choice1 == 'y' || choice2 == 'n')
		{
			cout << "\nNumber of items being purchased ?:";
			cout << (0 - 100);

			//initialize variables
			Int number = 0;
			while (number < 100)
			{
				cout << "Please enter the number of times the user enters: 0 time, 1 time, 2 times, 3 times  ";
				cin >> number;
				switch (number)
				{
				case 0:
					total += 0 time;
					break;
				case 1:
					total += 1 time;
				case 2:
					total += 2 times;
					break;
				case 3:
					total += 3 times;
					break;

				}// end switch
			} // end for
			cout << " the total number of times each number (0-3), was selected " << total << endl;
			system("pause");
			return 0;
}

what i am suppose to do:
I am a programmer for a grocery store and they need a special program to be written to count the number of times 4 items are purchased.
Each item in the store has an integer number associated with it. To keep things simple, they are 0 through 100. The store is only interested in items 0,1,2 and 3. Your job here is to write a program using a while loop using a priming read that asks the user if they want to continue? 1 for yes, 2 for no.
In the loop i have to ask the user to enter the number of the item being purchased (0-100). Using a switch structure, count the number of times the user enters a 0,1,2 or 3.
After the user ends the loop, display the total number of times each number (0-3), was selected.
thank you.
Last edited on
please use code tags.
Hey. Could you please edit your post and include all the code between code tags <> - http://www.cplusplus.com/articles/jEywvCM9/

And please paste all the errors you get here.

Edit:

1
2
3
4
double 0 time;
double 1 time;
double 2 times;
double 3 times;


Variable names cant start with a number. Nor can they have spaces.

cin >> choice1 >> Choice2;

its choice2, not Choice2.

Int number = 0;

Its int not Int

1
2
3
4
5
6
7
8
9
total += 0 time;
					break;
				case 1:
					total += 1 time;
				case 2:
					total += 2 times;
					break;
				case 3:
					total += 3 times;


There is nothing in your program called total... Did you even read through your program, these errors are incredibly hard to miss.

Edit 2: Im starting to suspect that your professor gave you this as a homework and told you to fix the code, and that you just took advantage of us. Cant prove that though.

Edit 3: After some thought, this is way too fishy and terrible, pretty sure my suspicions are correct.
Last edited on
first error is:
char choice1;
second error is:
1
2
   }// end switch
} // end for 

third error;
1
2
3
 system("pause");
	return 0;
}

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
#include <iostream>
#include <cstring>
#include <windows.h>
using namespace std;

int main()
{
do ///what is this for?
///declare variables
int number = 0;
char choice1, choice2;
double 0 time; /// the var name belongs in front of the number equaling it
double 1 time; /// the var name belongs in front of the number equaling it
double 2 times; /// the var name belongs in front of the number equaling it
double 3 times; /// the var name belongs in front of the number equaling it

{ ///this is randomly here
cout << "\nDo you want to continue? (y/n)? ";
cin >> choice1 >> Choice2;
if (choice1 == 'y' || choice2 == 'n')
{ ///where does this end?
cout << "\nNumber of items being purchased ?:";
cout << (0 - 100);

///initialize variables
Int number = 0;
while (number < 100)
{
cout << "Please enter the number of times the user enters: 0 time, 1 time, 2 times, 3 times ";
cin >> number;
switch (number)
{
case 0:
total += 0 time;
break;
case 1:
total += 1 time;
case 2:
total += 2 times;
break;
case 3:
total += 3 times;
break;

}/// end switch
} /// ends the loop
cout << " the total number of times each number (0-3), was selected " << total << endl;
system("pause");
return 0;
}

hey TarikNeaj I agree. was this a code correction assignment?
Last edited on
first of all this is my first time doing a program by my self.
No, the professor did not told me to fix the code, i am trying to do the code my self but its hard and confusing.
I just need advises, i absolutely don't need you to do the assignment for me.
So if you would like to help, please i am open ears. But if you don't, please just don't reply back to my post OKAY.
Thanks again for those that are trying to help.
hey hey sheesh was just telling what i looked like. There are some errors that I pointed out in my post look at the comments.
Last edited on
Thats exactly what someone with a code correction assignment would say.

Im mean lets be honest. In the code you've shown, you declare variables and then use them, which is the way to do things. But then you just randomly start using "total" without creating it. You named 2 variables choice1 and choice 2, then you try and put the numbers before the word time and times, with a space aswell. Did you lose your brain in the middle of programming this or is this actually a code correction assignment. (Not trying to be mean, although it might come across that way)

My suggestion is - https://www.youtube.com/playlist?list=PLAE85DE8440AA6B83

Watch buckys tutorials, and you'll have all the basics of c++ nailed down. Code along side with him. I also actually did tell you where most of the errors came from in my first post.
Last edited on
did you realize that he is basing C++ off of C. He is declaring variables like using #define
No i did not lose my brain since I am still talking to you.
And i didn't have an idea that a person with a code correction will sound "like me".
I am not trying to be rude but if you are not helping then don't get on the way. (Not trying to be mean, although it might come across that way).
Please if you don't believe me just don't comment in my post.
Thanks.
I have helped you though, even if I suspect something. Like I said, I pointed out most of the errors and told you how to fix them. And I gave you great tutorials. So why dont you fix the code with the fixes we have provided you, and then post it here so we can provide further help ?
Working on it .....
Looking forward to helping you further :) But could you just tell me, why you at the top declared int perfectly - int number = 0; But then were not able to declare an int nor ever noticing that you declared it wrong - Int number = 0;
Last edited on
conspiracy theorist....
Topic archived. No new replies allowed.