Run-Time Check Failure #3 - The variable 'q' is being used without being initialized. and bool question

closed
Last edited on
It's exactly as the compiler says. Look at line 102. What's the difference between q and 'q'? Also think about your other char variables a, s, l, q, What are their values? If you want to use those for whatever reason, what's the point of having a char choice variable?
here is the following errors i also get when i build it.

Warning 1 warning C4101: 'a' : unreferenced local variable 32 1 lab 1 test
Warning 2 warning C4101: 's' : unreferenced local variable 32 1 lab 1 test
Warning 3 warning C4101: 'q' : unreferenced local variable 32 1 lab 1 test
Warning 4 warning C4101: 'l' : unreferenced local variable 32 1 lab 1 test


"It's exactly as the compiler says. Look at line 102. What's the difference between q and 'q'? Also think about your other char variables a, s, l, q, What are their values? If you want to use those for whatever reason, what's the point of having a char choice variable?"

what do you mean by that? I am little lost like I said I have been out for a while I hate that i have done that to my self. I also edited the program for the q and its still giving me this.


i went ahead and took out char also.

here is a video of what is happening with the program: https://www.youtube.com/watch?v=zTLo99EHOsE

Waiting on it to process, but i am stuck with no clue what to do honestly.
You want it to execute once through for whatever choice you put in. Think about it: your break condition is while choice != 'q'. When you enter 'a', does the choice ever become 'q'?

And again, q is a variable name. 'q' is a specific character.

To put it bluntly, you have extraneous and unnecessary char variables named q, s, l, q. What you want is to assign those letters as character values to your choice variable and compare them using your switch statement.
okay i see what you mean. I went ahead and updated my code to 'q', but like in the video i am having a issue now with it looping and i am thinking its the if else inside of case 'a'. like i said though i am not sure. Its just weird cause before I did a program for a class and it worked fine.

here is the code from that program.

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
#include <iostream>
#include <string> 
#include <iomanip>

using namespace std;

int main ()
{
	string item;
    float totalCost = 0;
    char choice;
	double price;
	double totalPrice = 0;
	char productName[100];
	char a, t, q, c;
    	



    do{
    cout << "\n Welcome to Chad's shopping cart calculator" << endl << endl;
    cout << "Here are your following options." << endl;
	cout << "a. Add to your cart" << endl;
    cout << "t. your running total." << endl;
    cout << "c. to clear the screen(remove clutter)" << endl;
	cout << "q. To quit the program." << endl;
    cout << "please enter your choice: "; 
	cin >> choice;
	
	switch (choice){
	case 'a':
	cout << "Please enter the name of the item: ";
 	cin.ignore(100, '\n');
	cin.getline (productName, 100, '\n'); 
	cout << "\n Please enter in the price: ";
	cin >> price;
	cout << endl << "You have selected: " << productName << " for the price of: $" << price << endl;
	cout << endl;
	totalPrice += price;  
	break;
	case 't':
	cout<< endl << "Your running total is: " << totalPrice << setprecision(2);
	break;
	case 'c':
	system("CLS");
	break;
	case 'q':
	cout << endl << "Thank you for using Chad's shopping cart." << endl;
	cout << "Enjoy the rest of your day." << endl;
	return 0;
	break;
	}
	}while(choice !=q );

}


which still works to this day even with the letters as chars.

yea I am calling my self stupid right now for not being able to figure this out.. ugh...

looks like its my if else loop that is causing the repeat loop.

any idea what could be wrong with it?
Last edited on
Your looping error has something to do with line 49 in your planets program. Comment that out and see what happens. I'm not entirely sure where the logical error is yet, because I'm working on something myself right now, but ask yourself this: what is the purpose of what you want from that line of code? Then compare it to the actual logic of what happens.
"Your looping error has something to do with line 49 in your planets program. Comment that out and see what happens. I'm not entirely sure where the logical error is yet, because I'm working on something myself right now, but ask yourself this: what is the purpose of what you want from that line of code? Then compare it to the actual logic of what happens."

Very true. I tried that and I am still having issues with it looping. I know that the if else loop is what is throwing it into a loop, but i have break; at each end of the program.

updated code**
Last edited on
Topic archived. No new replies allowed.