Hi dreaweiss, welcome to the forum.
I'll outline the problems with your code:
1.) On line 4, you declare three variables. Two of them, namely 'setprecision' and 'setw' are also the names of functions found in the 'std' namespace. Normally, one would access these functions by using the scope-resolution operator like so:
std::setprecision
and
std::setw
. However, since you've elected to use
using namespace std;
in global scope, the compiler thinks that your function calls on lines 28 and 30 are actually attempts to treat your variables on line 4 as functions.
The way to fix this is to simply remove the offending variables on line 4, since you aren't even using them for anything. Your fourth line of code should therefore only declare 'again'.
2.) Technically, line 4 shouldn't just declare 'again', but also define / initialize it. If you do not give 'again' an initial value, you're invoking undefined behavior on line 5 when you enter the while-loop because 'again' contains garbage, and you're attempting to access it. Fix this by initializing 'again' on line 4 (so that it may enter the while-loop).
In addition, 'again' shouldn't be an
int
, it should be a
char
.
3.) There's a discrepancy in the condition of your while-loop on line 5. What you probably meant to write was
while(again == 'y' || again == 'Y')
, not
while(again == 'Y' || again == 'Y')
.
4.) The while-loop on line 5 has no body. The semi-colon (';') immediately following the parentheses on line 5 is the cause of this. You will have to remove the semi-colon and add some braces ('{' and '}') around all of the code that should be part of the while-loop's body.
That should be a good start. I've appended this basic code as a guide:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
#include <iostream>
#include <iomanip>
int main() {
char again = 'y';
while (again == 'y' || again == 'Y') {
//Do things in here...
}
return 0;
}
|