Beginner Help Plz :D

This is a discussion on Beginner Help Plz :D within the C++ Programming forums, part of the General Programming Boards category; Hey, I just started on C++ beginner excercises and this error is making me want to puill my hair out.. ...

  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
    32,855
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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, 03:07 PM
  2. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 10: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, 12:48 PM
  5. Anyone plz help me
    By Rose_Flowers in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 09-17-2003, 01:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21