Something Wrong, can not figure it out? (VB10 C++)

I am having a problem with IF statments. The if statment is written correctly (i think) but when the if statment (in bold) comes up, it redefines the number to anything that is in there. It will build. Please help.

CODE:

#include
#include
using namespace std;

int main()
{
system ("color 16");
int assigninput = 1; //What number the string is on for entering
char anotherassignment; //Is there another assignment you need to enter?
char stop;
string assign1; //Assignment Name
string assign2;
string assign3;
string assign4;
string assign5;
string assign6;
string assign7;
string assign8;
string assign9;
string assign10;
string subjassign1; //Subject Name: Number matches with assign#
string subjassign2;
string subjassign3;
string subjassign4;
string subjassign5;
string subjassign6;
string subjassign7;
string subjassign8;
string subjassign9;
string subjassign10;
int completion1 = 0; //Yes = 1 No = 0
int completion2 = 0; //Yes = 1 No = 0
int completion3 = 0; //Yes = 1 No = 0
int completion4 = 0; //Yes = 1 No = 0
int completion5 = 0; //Yes = 1 No = 0
int completion6 = 0; //Yes = 1 No = 0
int completion7 = 0; //Yes = 1 No = 0
int completion8 = 0; //Yes = 1 No = 0
int completion9 = 0; //Yes = 1 No = 0
int completion10 = 0; //Yes = 1 No = 0
anotherassignment = 'y';
stop = 'n';
if (stop = 'n')
{
switch (assigninput)
{
case 1:
cout<<"Input first assignment's subject:"<<endl;
cin>>subjassign1;
cout<<"Input first assignment's name:"<<endl;
cin>>assign1;
cout<<"Ok, do you have another assignment? (y/n)"<<endl;
cin>>anotherassignment;
if (anotherassignment = 'y')
{
assigninput = assigninput + 1;
break;
}
if (anotherassignment = 'n')
{
stop = 'y';
break;
}
else
{
cout<<"test"<<endl;
break;
}
}
}
cout<<"Welcome to the Homework Sorter. Here are the Current Assignments:"<<endl;
if (assigninput = 1)
{
cout<<"1. "<< assign1 <<" in "<< subjassign1 <<" is"<<endl;
[b]if (completion1 = 1)
cout<<"Completed."<<endl;
if (completion1 = 0)
cout<<"Not Completed."<<endl;[/b] }
system ("PAUSE"); //FOR DEBUGGING ONLY
return 0;
}

Comments

  • [color=Blue]The equality operation in all your IF() statement, not only in bold, but in all of them -- must be a double equality sign.

    Example of bad IF() statement:
    [/color][code]
    if (completion1 [color=Red]=[/color] 1)
    {
    }
    [/code]
    [color=Blue]Example of good IF() statement:
    [/color][code]
    if (completion1 [color=Red]==[/color] 1)
    {
    }
    [/code][color=Blue]The IF() with only one equality sign can be proper, but only in certain cases and that style is not preferred - it makes code unreadable. In general, one equal sign mean ASSIGNMENT of some value to other value.

    Here is an example of IF() with only one sign:[/color]
    [code]
    if (completion = errorCode)
    {
    [color=Green]// BLOCK OF CODE A)[/color]
    }
    [/code][color=Blue]In this case it means:
    1. Assign the value from [italic][color=Green]errorCode[/color][/italic] into variable [italic][color=Green]completion[/color][/italic]
    2. Check the [color=Green][italic]completion[/italic][/color] for zero and if it is not zero, then execute [color=Green]BLOCK A)[/color]

    However, in your case I assume that you just want to compare the variable to a value of constant, like 0 or 1 - in this case you need ==.
    [/color]
  • Wow am i stupid...thanks.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories