Here's the error I get in Visual C++:
1>------ Build started: Project: testing stuff, Configuration: Debug Win32 ------
1> testing stuff.cpp
1>c:\users\hp\documents\visual studio 2010\projects\testing stuff\testing stuff\testing stuff.cpp(33): error C2065: 'numberOfColumns' : undeclared identifier
1>c:\users\hp\documents\visual studio 2010\projects\testing stuff\testing stuff\testing stuff.cpp(33): error C2078: too many initializers
1>c:\users\hp\documents\visual studio 2010\projects\testing stuff\testing stuff\testing stuff.cpp(39): error C2065: 'numberOfColumns' : undeclared identifier
1>c:\users\hp\documents\visual studio 2010\projects\testing stuff\testing stuff\testing stuff.cpp(39): error C2078: too many initializers
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I have no idea how to solve this, since choice 1 and choice 2 both depend on two variables, but Visual C++ wants me to only let choice 1 and choice 2 depend on one variable each!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
#include "stdafx.h"
#include <iostream>
using namespace std;
void chooseValues(int choice) //choose values of y and numberOfColumns
{
cout << "Please enter the constant number: ";
if(choice == 1)
{
int y;
cin >> y;
int choice1(y);
}
else if(choice == 2)
{
int x;
cin >> x;
int choice2(x);
}
else
{
cout << "Sorry, you didn't choose 1 or 2.\n";
}
}
void choice1(int y, int numberOfColumns)
{
cout << "\nHere are the values of x % " << y << ": \n";
for(int iii = 0; iii < ( (numberOfColumns + 1) * y); iii++)
{
cout << iii << " % " << y << " = " << iii % y << ".";
if( iii % y == y - 1 )
cout << "\n";
else
cout << "\t";
}
}
void choice2(int x, int numberOfColumns)
{
cout << "\nHere are the values of " << x << " % y: \n";
for(int iii = 0; iii < ( (numberOfColumns + 1) * x); iii++)
{
cout << iii << " % " << x << " = " << iii % x << ".";
if( iii % x == x - 1 )
cout << "\n";
else
cout << "\t";
}
}
int main()
{
cout << "This program outputs values of x % y.\n";
cout << "Enter '1' if you want to see values of x % constant number.\n";
cout << "Enter '2' if you want to see values of constant number % y.\n";
int choice;
cin >> choice;
cout << "Please enter how many columns you want: ";
int numberOfColumns;
cin >> numberOfColumns;
int chooseValues(choice);
cout << "\n Have a great day! \n";
return 0;
}
|