Help

I have an assigment due and a I am struggling, this is what I have so far.

#include<iostream>
#include<cmath>

using namespace std;

int main()
{
cout<<"Metropolis 2019 Winter Street Treatment Designation\n\n";
char name[100] ;

float temp;
cout<<"What is the temperature in degrees(f)? ";
cin>>temp;

float depth=0;
cout<<"How much new snow depth (in inches)? ";
cin>>depth;

std::string T,M,L;
T="Truckline";
M="Main Streets";
L="Local Streets";

cout<<"Which one do you choose (TML)? ";
cin>>T,M,L;


if(((depth > 0.75) && (temp < 8)) && (T,M,L == T)){


cout<<"Given the temperature is" <<temp<< "degrees and" <<depth<< "inches of snow accumulation.\n" <<(T,M,L)<< "will be plowed and salted." << endl;


}

return 0;

}



The instructions are, when snow depth exceeds 0.75 inches on trunklines and 1.5 inches on Major Streets and 3.25 inches on Local Streets. City crews will start plowing and or salting.
if the temperature is below 8 degrees then salting will not be done.

if anyone can help. I will appreciate it. thanks
1
2
3
4
5
6
cin>>T,M,L;
(T,M,L == T)

char choice;
cin >> choice;
if(choice == 'T')
std::string T,M,L;
When you write that, the compile thinks T, M, L are variables that will hold data.

cin>>T,M,L; is interpreted as
1
2
3
cin>>T;
M;
L;

and hence interpreted as cin >> T;

Similarly (T,M,L == T) is read by the compiler as (L == T).

So like ne555 said, use a char variable to hold the choice that the user inputs and then compare the variable with single character constants 'T', 'L', 'M' etc.
1
2
3
4
5
6
7
8
9
10
11
char choice;
cin >> choice;

if(choice == 'T')
   std::cout << "You typed T!";
else if (choice == 'M')
   std::cout << "You typed M!";
else if (choice == 'L')
   std::cout << "You typed L!";
else 
   std::cout << "You didn't type T, M or L!";
thanks guys...

But how would I get lets say 'T' to cout as 'Trunklines' ?

My final output after the questions are answered shoud look something like this:

Given the temperature is 10 degrees and 9 inches of snow accumulation ( T, M or L should print here) will be plowed and salted.

and if the temperature is below 8 degrees it will not be salted!

could I do something like this

if (choice == 'T') && (temp >> 8) && (depth >> 0.75)

std::cout<<"Given the temp is" <<temp<<"degrees and" <<depth<< "inches of snow accumulation" <<choice<< will be plowed and salted.

else if (choice == 'T') && (temp << 8) && (depth >> 0.75)
std::cout<<"Given the temp is" <<temp<<"degrees and" <<depth<< "inches of snow accumulation" <<choice<< will be plowed and not salted.


Instead of writing std::cout << choice; you can write std::cout << "Trunklines"; directly since the if-statement makes sure that choice == 'T'.

just an example
1
2
3
4
5
6
7
8
9
10
11
char choice;
std::cin >> choice;
if (choice == 'T') {
   std::cout << "You chose Trunklines";
}
else if (choice == 'S') {
   std::cout << "You chose Superman!";
}
else {
   std::cout << "Boo you picked none";
}
Topic archived. No new replies allowed.