#include <iostream>
#include<cstring>
usingnamespace 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.
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.
#include <iostream>
#include <cstring>
#include <windows.h>
usingnamespace 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?
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.
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)
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.
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 ?
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;