Thread: Beginner Help Plz :D

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    3

    Question Beginner Help Plz :D

    Hey, I just started on C++ beginner excercises and this error is making me want to puill my hair out..

    Here's the code:
    Code:
    #include<iostream>
    using namespace std;
    
    int main()
    {
    	int choice;
    	int run;
    
    	while(run!= 1){
    		cout << "Soda Selections" << endl;
    		cout << "---------------" << endl;
    		cout << "Coca Cola[1]" << endl;
    		cout << "Diet Coca Cola[2]" << endl;
    		cout << "Sprite[3]" << endl;
    		cout << "Sprite Zero[4]" << endl;
    		cout << "Dasani[5]" << endl;
    		cout << "Quit[6]" << endl;
    		cout << "**Use the numbers to choose your soda!**"<< endl;
    		cin >> choice;
    		switch(choice)
    		{
    			case 1:
    				cout << "You've chosen Coca Cola!" << endl;
    				break;
    			case 2:
    				cout << "You've chosen Diet Coca Cola!" << endl;
    				break;
    			case 3:
    				cout << "You've chosen Sprite!" << endl;
    				break;
    			case 4:
    				cout << "You've chosen Zero Sprite!" << endl;
    				break;
    			case 5:
    				cout << "You've chosen Dasani!" << endl;
    				break;
    			case 6:
    				return 0;
    			default:
    				cout << " Please make another selection.";
    		}
    	}
    	system("PAUSE");
    }
    I keep getting this:
    Run-Time Check Failure #3 - The variable 'choice' is being used without being initialized.

    Help Please?

  2. #2
    Registered User
    Join Date
    Nov 2010
    Posts
    15
    runs fine here

    maybe its a warning

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > while(run!= 1)
    What's the value of run?

    I mean, you can simply fix the problem by initialising things
    int choice = 0;
    int run = 0;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Nov 2010
    Posts
    3
    heh, thanks Salem, I forgot about initializing it works now

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. project .... help plz plz plz
    By Hitchhik3R in forum C Programming
    Replies: 13
    Last Post: 10-24-2010, 02:07 PM
  2. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 09:19 PM
  3. [Request] Need Help Plz
    By TylerD in forum Tech Board
    Replies: 4
    Last Post: 01-03-2009, 09:54 AM
  4. Same old beginner question...
    By Sharmz in forum C Programming
    Replies: 15
    Last Post: 08-04-2008, 11:48 AM
  5. Anyone plz help me
    By Rose_Flowers in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 09-17-2003, 12:01 PM