basic loop error

Posts 1–3 of 3 · Page 1 of 1
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;
}
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;
}
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....
Posts 1–3 of 3 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

Talk with us