Help asap c++ code

Watch this thread
TofuB
Badges: 1
Rep:
? You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#1
Report Thread starter 3 months ago
#1
Hello I can't get 'TotalA' to return in my int main() my assignment is due for sunday and I need this coding completed please can somebody help?

int main()
{
Welcome();
Disclaimer();
system("CLS");
DisplayMenu();

{
switch (noption)
{
case 1:
{ cout << "You have chosen the Anxiety path, please answer the following questions to determine your mindfullness technique.\n";
system("pause");
system("CLS");
AQuSetOne();
cout << TotalA;
if (TotalA<10)
{
cout << "Based upon your answers, it is suggested that you continue onto route 2...";
system("pause");
system("CLS");




int AQuSetOne()
{
int A = 0;
int B = 1;
int C = 2;
int D = 3;

cout << "Do you feel nervous, restless or tense ?\n"; //QU1
cout << "\n A) Not at all";
cout << "\n B) Several Days";
cout << "\n C) More than half the days";
cout << "\n D) Nearly every day\n";
cin >> Answ;

while (Answ != 'A' && Answ != 'B' && Answ != 'C' && Answ != 'D' || cin.fail())
{
cout << "Please enter A, B , C OR D";
cout << "Do you feel nervous, restless or tense ?\n"; //QU1
cout << "\n A) Not at all";
cout << "\n B) Several Days";
cout << "\n C) More than half the days";
cout << "\n D) Nearly every day\n";
cin >> Answ;
}
if (Answ == 'A')
{

TotalA + A;

}
if (Answ == 'B')
{

TotalA + B;

}
if (Answ == 'C')
{
TotalA + C;

}
else
{
TotalA + D;

}
cout << "Are you having difficulty stopping or controlling worry?\n"; //QU3
cout << "\n A) Not at all";
cout << "\n B) Several Days";
cout << "\n C) More than half the days";
cout << "\n D) Nearly every day\n";
cin >> Answ;
while (Answ != 'A' && Answ != 'B' && Answ != 'C' && Answ != 'D' || cin.fail())
{
cout << "Please enter A, B , C OR D";
cout << "Are you having difficulty stopping or controlling worry??\n"; //QU1
cout << "\n A) Not at all";
cout << "\n B) Several Days";
cout << "\n C) More than half the days";
cout << "\n D) Nearly every day\n";
cin >> Answ;
}
if (Answ == 'A')
{

TotalA + A;

}
if (Answ == 'B')
{

TotalA + B;

}
if (Answ == 'C')
{
TotalA + C;

}
else
{
TotalA + D;

}
cout << "Worrying too much about different things?\n"; // QU4
cout << "\n A) Not at all";
cout << "\n B) Several Days";
cout << "\n C) More than half the days";
cout << "\n D) Nearly every day\n";
cin >> Answ;

while (Answ != 'A' && Answ != 'a' && Answ != 'b' && Answ != 'c' && Answ != 'd' && Answ != 'B' && Answ != 'C' && Answ != 'D' || cin.fail())
{
cout << "Please enter A, B , C OR D";
cout << "Worrying too much about different things?\n"; //QU1
cout << "\n A) Not at all";
cout << "\n B) Several Days";
cout << "\n C) More than half the days";
cout << "\n D) Nearly every day\n";
cin >> Answ;
}
if (Answ == 'A')
{

TotalA + A;
}
if (Answ == 'B')
{

TotalA + B;
}
if (Answ == 'C')
{
TotalA + C;
}
else
{

cout << "Are you so restless that it is hard to sit still?\n"; //QU1
cout << "\n A) Not at all";
cout << "\n B) Several Days";
cout << "\n C) More than half the days";
cout << "\n D) Nearly every day\n";
cin >> Answ;

while (Answ != 'A' && Answ != 'a' && Answ != 'b' && Answ != 'c' && Answ != 'd' && Answ != 'B' && Answ != 'C' && Answ != 'D' || cin.fail())
{
cout << "Please enter A, B , C OR D";
cout << "Are you so restless that it is hard to sit still?\n"; //QU1
cout << "\n A) Not at all";
cout << "\n B) Several Days";
cout << "\n C) More than half the days";
cout << "\n D) Nearly every day\n";
cin >> Answ;
}
if (Answ == 'A')
{

TotalA + A;

}
if (Answ == 'B')
{

TotalA + B;

}
if (Answ == 'C')
{
TotalA + C;

}
else
{
TotalA + D;

}
cout << "Are you easily annoyed or irritable?\n"; //QU1
cout << "\n A) Not at all";
cout << "\n B) Several Days";
cout << "\n C) More than half the days";
cout << "\n D) Nearly every day\n";
cin >> Answ;

while (Answ != 'A' && Answ != 'a' && Answ != 'b' && Answ != 'c' && Answ != 'd' && Answ != 'B' && Answ != 'C' && Answ != 'D' || cin.fail())
{
cout << "Please enter A, B , C OR D";
cout << "Are you easily annoyed or irritable?n"; //QU1
cout << "\n A) Not at all";
cout << "\n B) Several Days";
cout << "\n C) More than half the days";
cout << "\n D) Nearly every day\n";
cin >> Answ;
}
if (Answ == 'A')
{

TotalA + A;

}
if (Answ == 'B')
{

TotalA + B;

}
if (Answ == 'C')
{
TotalA + C;

}
else
{
TotalA + D;

}
cout << "Do you feel afraid that something awful might happen?\n"; //QU1
cout << "\n A) Not at all";
cout << "\n B) Several Days";
cout << "\n C) More than half the days";
cout << "\n D) Nearly every day\n";
cin >> Answ;

while (Answ != 'A' && Answ != 'a' && Answ != 'b' && Answ != 'c' && Answ != 'd' && Answ != 'B' && Answ != 'C' && Answ != 'D' || cin.fail())
{
cout << "Please enter A, B , C OR D";
cout << "Do you feel afraid that something awful might happen?\n"; //QU1
cout << "\n A) Not at all";
cout << "\n B) Several Days";
cout << "\n C) More than half the days";
cout << "\n D) Nearly every day\n";
cin >> Answ;
}
if (Answ == 'A')
{

TotalA + A;

}
if (Answ == 'B')
{

TotalA + B;

}
if (Answ == 'C')
{
TotalA + C;

}
else
{
TotalA + D;

}
system("pause");
system("CLS");

}
return TotalA;
}
0
reply
navkan
Badges: 7
Rep:
? You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#2
Report 3 months ago
#2
Have you tried just printing total A and then just return 0 after that ?
0
reply
Icy Wolf
Badges: 10
Rep:
? You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
#3
Report 3 months ago
#3
(Edit: TSR doesn't support code formatting I think, but any text in my reply contained in the `` characters is code)

I know that this reply is too late, but on lines 42 - 52 (and similar parts of the code) there are several issues.
First, you're just using `TotalA + A` not `TotalA += A`. Now I know my C++ is fairly rusty but I'm fairly sure you can't just do `TotalA + A` because that just returns the value of `TotalA + A`; it's not an assignment.
Also, you use `if` statements rather than `else if`, meaning that the final
```
} else {
TotalA + D
}
```
will always run if the previous selection (`if Answ == "C"`) is false, i.e. if the user enters A, B, or D. So if the user selects option A, TotalA would be incremented by A first and then D.

As an extra suggestion, it's best to label functions and variables with camelCase (first letter is lowercase), and leave PascalCase (first letter is uppercase) for user-defined data types.

If you were to really perfect this, I'd suggest creating a function with parameters of the question, the answer scores, and the function to call for each different answer.

I haven't used C++ in like 4 years so if any of this is wrong just tell me :P
Hope this helped for future assignments!
Last edited by Icy Wolf; 3 months ago
0
reply
X

Quick Reply

Attached files
Write a reply...
Reply
new posts
Back
to top
Latest
My Feed

See more of what you like on
The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

Personalise

Have you done work experience at school/college?

Yes (154)
42.08%
Not yet, but I will soon (66)
18.03%
No (146)
39.89%

Watched Threads

View All