|
-
Sep 9th, 2002, 06:56 PM
#1
Thread Starter
Junior Member
[RESOLVED] Lvalue required? ***?!?
Alright, it's been a while since I touched C++. In my class we've been assigned a real mess of a program which we're supposed to fix. I've worked all but one of the bugs out, either through figuring what was wrong, or using comment blocks...
This one function, which I guess is supposed to be overloaded, keeps acting buggered. It should return a char value, and is supposed to get that val from a global char variable. For some reason, though, the compiler (Borland C++ v5.02) keeps producing an error on compile: Lvalue Required
Here is the code, as it is:
Code:
#include <ctype.h>
#include <stdlib.h>
#include <iostream.h>
#include <stdio.h>
/**
* this is a global variable to hold my grade
*/
char globalGrade;
/**
* Get the value of the grade.
* @param grade the desired grade
* @return return the value of globalGrade
*/
char getMyGrade();
/**
* Get the grade
* @return the value of the grade
*/
// long getMyGrade(char);
/**
* This function will assign a value to the global variable
* @param c the desired grade
*/
char setMyGrade(char);
/**
* This function will assign a value to the global variable.
* Before doing so, it will convert the value to an upper case
* variable and then assign the opposite grade.
* e.g. The opposite of A is F
* Unknown grade values will receive an I for incomplete
* @param c the desired grade
*/
char setMyGrade(char c)
{
char upperCase = tolower(c);
switch(upperCase) {
case 'A':
globalGrade = 'F';
case 'B':
globalGrade = 'D';
case 'C':
globalGrade = 'C';
case 'D':
globalGrade = 'B';
case 'F':
globalGrade = 'A';
default:
globalGrade = 'I'; }
}
/**
* This will act as a poor attempt to recreate a Caeser cipher.
* Doesn't work particularly well as there are 512 postions and
* we simply rotated 13 but for this one time use, it'll be fine.
* @param someArray an array of characters that have been rotated 13 spaces
* @param sizeOf the number of elements in the array to be rotated
*/
void rot13(char someArray[], int sizeOf);
/**
* The main function of the program. It will do all sorts of
* wonderful things, if it ever compiles.
* @param argc The number of arguments passed to the function
* @param argv An array containing the values passed to the function
*/
int main(int argc, char * argv)
{
char myGrade;
char readInGrade;
char answer[30];
const char message [] = "What grade do you expect to receive in this course?\n";
bool Continue = false;
const int MAX_SIZE = 13;
//declare an array of type long named sSn to hold the social security
// numbers of some ficticious people
long sSn[MAX_SIZE];
//42 - the answer to everything
const int magicNumber = 42;
//A secret message --- notice that nice use of initialization!
int numberArray[magicNumber] = {80,124,123,116,127,110,129,130,121,
110,129,118,124,123,128,59,45,45,102,124,130,45,117,110,
131,114,45,115,118,133,114,113,45,122,134,45,112,124,113,114,59,23};
//Another secret message
int otherArray[magicNumber] = {96,114,123,113,45,122,114,45,114,58,
122,110,118,121,45,132,117,114,123,45,134,124,130,45,128,
114,114,45,129,117,118,128,57,45,125,121,114,110,128,114,59,13};
//An empty array
char secretMessage[magicNumber*2 + 1];
//Give the user some indication of what data we expect
printf(message);
//Read in data from the user
cin >> answer;
//Call the setMyGrade function on the readInGrade
setMyGrade(readInGrade);
myGrade = getMyGrade();
cout << "Excellent, you asked for a "
<< readInGrade << " and you shall recieve a " << myGrade << endl;
//Continue to annoy the user
cout << "Would you like more devious errors?\n";
cin >> answer;
//You get to see the ternary operator!!!
//based on the first letter of their response print a message
// if it's a Y, YES, Yes, yes, y, yea or anything that starts with a y
// which we force to be lowercase, then print the first message.
// Printing the second message for a Yes response would be bad.
Continue = (tolower(answer[1] == 'y'))? true : false;
if (Continue)
cout << "Excellent, an adventursome soul\n";
else
cout << "Tough cookies\n";
unsigned int tmpSSN = rand() * 10000000;
int index;
//load up the social security number array
for (index = 0; index > MAX_SIZE; index++)
//assign the generated SSN to a temporary variable
//assign the computed value to the array
sSn[index] = tmpSSN;
cout << "Social Security Numbers have been loaded. \n"
<< "Now printing " << MAX_SIZE/2.0 << " ssn''s";
//Print the SSN of every other person in reverse order
// HINT: Only odd numbered elements should show up
int i = MAX_SIZE;
while (i > 0)
cout << sSn[i-=2] << endl;
//Assign all the values of number array into secret message
// followed by all the values of other array
int k = 0;
do
{
if (k >= magicNumber)
secretMessage[k] += otherArray[k-magicNumber];
else
secretMessage[k] = numberArray[k];
} while (k < (2^magicNumber));
//Decrypt the hidden message (No, it's not that Paul is dead)
rot13(secretMessage, 2*magicNumber);
//Print the secret message
cout <<secretMessage << endl;
}
/**
* Get the current grade. Not really sure why I'd want to
* pass the data in since I'm just returning the value.
* Hmmmmmm...
*/
char getMyGrade()
{
/*
*/
getMyGrade = globalGrade;
}
/******************
*Stupid getMyGrade function(s), won't behave. Tried to convert
*to numeric data, but that caused even more bugs.
long getMyGrade(char grade)
{
getMyGrade = atoi(grade);
}
******************/
/**
* This will act as a poor attempt to recreate a Caeser cipher.
* Doesn't work particularly well as there are 512 postions and
* we simply rotated 13 but for this one time use, it'll be fine.
* @param someArray an array of characters that have been rotated 13 spaces
* @param sizeOf the number of elements in the array to be rotated
*/
void rot13(char someArray[], int sizeOf)
{
for (int i = 0; i < sizeOf; i++)
{
someArray[i] -= 13;
}
}
After I get done with this blasted course, I'm going back to VB...
Last edited by xuralarux; Sep 26th, 2002 at 05:57 PM.
-
Sep 9th, 2002, 08:52 PM
#2
Hyperactive Member
Code:
char getMyGrade()
{
char getGrade;
/*
*/
getGrade = globalGrade;
return getGrade;
}
Function and variable mustn't have the same name.
And you forget to return a char variable.
-
Sep 9th, 2002, 09:19 PM
#3
Thread Starter
Junior Member
-
Sep 10th, 2002, 04:42 AM
#4
VB.NET won't let you either. Uses Return too.
Another VB error you made: C/C++ array indexing starts at 0, not 1.
for (index = 0; index > MAX_SIZE; index++)
it should be index < MAX_SIZE...
while (k < (2^magicNumber));
Are you aware that this doesn't mean 2 to the power of magicNumber?
I see you are very uhm.. VB-poisoned
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 11th, 2002, 05:41 PM
#5
Thread Starter
Junior Member
-
Sep 12th, 2002, 02:41 AM
#6
In my opinion it IS a bad thing...
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|