Results 1 to 3 of 3
  1. #1
    gwentravolta's Avatar
    Join Date
    Jan 2009
    Gender
    male
    Location
    A cardboard Box
    Posts
    311
    Reputation
    9
    Thanks
    46

    basic loop error

    Ok. im a newb at c++. two days of learning. anyways, tell me what is wrong w/ this, because my computer just keept beeping, then froze!

    Code:
    // beeep.cpp : main project file.
    
    #include "stdafx.h"
    #include <iostream>
    using namespace std;
    
    void doBeep(int nob)
    {
    	while(nob!=0)
    		cout << "\a";
    		nob = nob-1;
    }
    
    int main()
    {
    	cout << "Enter how many \"beeps\" you would like:" << endl;
    	int nob;
    	cin >> nob;
    	doBeep(nob);
    	return 0;
    }


    Posts:
    10 posts []
    50 posts []
    100 posts []
    500 posts []

    Thanks:
    5 thanks []
    10 thanks []
    100 thanks []

    Profile:
    Make a signature []
    Set a profile picture []

    Hacks:
    Download and use a hack []
    Get a virus []
    ... or two... []
    Release my own hacks []



  2. #2
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    Yay! errors :P

    Quote Originally Posted by gwentravolta View Post
    Ok. im a newb at c++. two days of learning. anyways, tell me what is wrong w/ this, because my computer just keept beeping, then froze!
    Code:
    void doBeep(int nob)
    {
    	while(nob!=0)
    		cout << "\a";
    		nob = nob-1;
    }
    The problem is in ur while statement. If your going to give multiple intructions inside a loop you have to use brackets "{}". Your function should instead look like this:
    Code:
    while(nob!=0)
    {
     cout << "\a";
     nob = nob-1;
    }

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  3. #3
    zeco's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    Canada
    Posts
    683
    Reputation
    12
    Thanks
    78
    My Mood
    Cynical
    Quote Originally Posted by why06 View Post
    Yay! errors :P



    The problem is in ur while statement. If your going to give multiple intructions inside a loop you have to use brackets "{}". Your function should instead look like this:
    Code:
    while(nob!=0)
    {
     cout << "\a";
     nob = nob-1;
    }
    I didn't get to help. Sigh. The early bird gets the worm. We need more people with compile/runtime errors here....

Similar Threads

  1. [HelP] Wr Hack 'Loop' Error
    By DReS in forum C++/C Programming
    Replies: 4
    Last Post: 06-06-2010, 12:52 AM
  2. [HELP] Visual Basics 2010 error
    By myheroking in forum Visual Basic Programming
    Replies: 2
    Last Post: 05-02-2010, 11:01 AM
  3. [HELP] Visual Basic 2008 Error
    By myheroking in forum Visual Basic Programming
    Replies: 1
    Last Post: 05-02-2010, 11:00 AM
  4. Visual basic 2008 Express edition error?
    By AeroMan in forum Visual Basic Programming
    Replies: 1
    Last Post: 05-30-2009, 03:38 PM
  5. Error In Visual Basic 2008 Express Edition ( Thanking People Who Help )
    By Gunner03 in forum Visual Basic Programming
    Replies: 4
    Last Post: 02-14-2008, 01:45 PM

Tags for this Thread