Jump to content

C++ program trouble Immediate HELP SOS !!!

Go to solution Solved by Hunter259,
Just now, Runelight said:

what do u mean so how should i do with a single read in variable ??? Im new to C++ thats why

You are asking A or B you only need one variable to do that. 

int A = 0;
cout<<"Enter 1 for Blah, 2 for Yay.\n";
cin>>A;
if(A==1){
	cout<<"Blah.\n";
}
else cout<<"Yay.\n";

OR

cout<<(A==1 ? "Blah.\n" : "Yay.\n");

 

23 hours ago, Hunter259 said:

Tada. You learned.

So thats correct ???

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Runelight said:

So thats correct ???

I wouldn't have said tada otherwise.

Main Gaming PC - i9 10850k @ 5GHz - EVGA XC Ultra 2080ti with Heatkiller 4 - Asrock Z490 Taichi - Corsair H115i - 32GB GSkill Ripjaws V 3600 CL16 OC'd to 3733 - HX850i - Samsung NVME 256GB SSD - Samsung 3.2TB PCIe 8x Enterprise NVMe - Toshiba 3TB 7200RPM HD - Lian Li Air

 

Proxmox Server - i7 8700k @ 4.5Ghz - 32GB EVGA 3000 CL15 OC'd to 3200 - Asus Strix Z370-E Gaming - Oracle F80 800GB Enterprise SSD, LSI SAS running 3 4TB and 2 6TB (Both Raid Z0), Samsung 840Pro 120GB - Phanteks Enthoo Pro

 

Super Server - i9 7980Xe @ 4.5GHz - 64GB 3200MHz Cl16 - Asrock X299 Professional - Nvidia Telsa K20 -Sandisk 512GB Enterprise SATA SSD, 128GB Seagate SATA SSD, 1.5TB WD Green (Over 9 years of power on time) - Phanteks Enthoo Pro 2

 

Laptop - 2019 Macbook Pro 16" - i7 - 16GB - 512GB - 5500M 8GB - Thermal Pads and Graphite Tape modded

 

Smart Phones - iPhone X - 64GB, AT&T, iOS 13.3 iPhone 6 : 16gb, AT&T, iOS 12 iPhone 4 : 16gb, AT&T Go Phone, iOS 7.1.1 Jailbroken. iPhone 3G : 8gb, AT&T Go Phone, iOS 4.2.1 Jailbroken.

 

Link to comment
Share on other sites

Link to post
Share on other sites

23 hours ago, Hunter259 said:

I wouldn't have said tada otherwise.

wow so thats it ??? only that much huh wow thanks bros !! 

Link to comment
Share on other sites

Link to post
Share on other sites

You use a ternary as a short if/else statement.

 

if (choice =='A')

{

        typeA

}

 

else

{

     typeB

}

 

can be rewritten as choice == 'A' ? typeA : typeB;

 

What it's doing is checking if choice does equal 'A' and if it does it returns what's directly after the question mark and if it doesn't  then it returns what's after the colon.

Link to comment
Share on other sites

Link to post
Share on other sites

On 8/11/2016 at 10:01 PM, Runelight said:

What about this one  ,

 

char type ;

int college , hostel ;

cin>>type ;

(type==A)? college=200 : hostel=200

 

 so i have a doubt ,

if i want 

 

i=(type==A)? college=200 : hostel =200 ;

so what type should i declare i as ???

or will it print college or hostel value which is 200 directly ???

or what is the post-code of this program  ???

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, Runelight said:

 so i have a doubt ,

if i want 

 

i=(type==A)? college=200 : hostel =200 ;

so what type should i declare i as ???

or will it print college or hostel value which is 200 directly ???

or what is the post-code of this program  ???

I have no idea what on earth you are talking about. All that will do is set I to what ever the end result is. If it will let you do that at all. 

Main Gaming PC - i9 10850k @ 5GHz - EVGA XC Ultra 2080ti with Heatkiller 4 - Asrock Z490 Taichi - Corsair H115i - 32GB GSkill Ripjaws V 3600 CL16 OC'd to 3733 - HX850i - Samsung NVME 256GB SSD - Samsung 3.2TB PCIe 8x Enterprise NVMe - Toshiba 3TB 7200RPM HD - Lian Li Air

 

Proxmox Server - i7 8700k @ 4.5Ghz - 32GB EVGA 3000 CL15 OC'd to 3200 - Asus Strix Z370-E Gaming - Oracle F80 800GB Enterprise SSD, LSI SAS running 3 4TB and 2 6TB (Both Raid Z0), Samsung 840Pro 120GB - Phanteks Enthoo Pro

 

Super Server - i9 7980Xe @ 4.5GHz - 64GB 3200MHz Cl16 - Asrock X299 Professional - Nvidia Telsa K20 -Sandisk 512GB Enterprise SATA SSD, 128GB Seagate SATA SSD, 1.5TB WD Green (Over 9 years of power on time) - Phanteks Enthoo Pro 2

 

Laptop - 2019 Macbook Pro 16" - i7 - 16GB - 512GB - 5500M 8GB - Thermal Pads and Graphite Tape modded

 

Smart Phones - iPhone X - 64GB, AT&T, iOS 13.3 iPhone 6 : 16gb, AT&T, iOS 12 iPhone 4 : 16gb, AT&T Go Phone, iOS 7.1.1 Jailbroken. iPhone 3G : 8gb, AT&T Go Phone, iOS 4.2.1 Jailbroken.

 

Link to comment
Share on other sites

Link to post
Share on other sites

On 8/11/2016 at 10:17 PM, Hunter259 said:

I have no idea what on earth you are talking about. All that will do is set I to what ever the end result is. If it will let you do that at all. 

i mean would it print college=200 (or hostel=200) and also initialize those ???

EDIT : Or should I even need to use I = blah blah blah ..

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, Runelight said:

i mean would it print college=200 (or hostel=200) and also initialize those ???

EDIT : Or should I even need to use I = blah blah blah ..

You didn't code it to print anything.

Main Gaming PC - i9 10850k @ 5GHz - EVGA XC Ultra 2080ti with Heatkiller 4 - Asrock Z490 Taichi - Corsair H115i - 32GB GSkill Ripjaws V 3600 CL16 OC'd to 3733 - HX850i - Samsung NVME 256GB SSD - Samsung 3.2TB PCIe 8x Enterprise NVMe - Toshiba 3TB 7200RPM HD - Lian Li Air

 

Proxmox Server - i7 8700k @ 4.5Ghz - 32GB EVGA 3000 CL15 OC'd to 3200 - Asus Strix Z370-E Gaming - Oracle F80 800GB Enterprise SSD, LSI SAS running 3 4TB and 2 6TB (Both Raid Z0), Samsung 840Pro 120GB - Phanteks Enthoo Pro

 

Super Server - i9 7980Xe @ 4.5GHz - 64GB 3200MHz Cl16 - Asrock X299 Professional - Nvidia Telsa K20 -Sandisk 512GB Enterprise SATA SSD, 128GB Seagate SATA SSD, 1.5TB WD Green (Over 9 years of power on time) - Phanteks Enthoo Pro 2

 

Laptop - 2019 Macbook Pro 16" - i7 - 16GB - 512GB - 5500M 8GB - Thermal Pads and Graphite Tape modded

 

Smart Phones - iPhone X - 64GB, AT&T, iOS 13.3 iPhone 6 : 16gb, AT&T, iOS 12 iPhone 4 : 16gb, AT&T Go Phone, iOS 7.1.1 Jailbroken. iPhone 3G : 8gb, AT&T Go Phone, iOS 4.2.1 Jailbroken.

 

Link to comment
Share on other sites

Link to post
Share on other sites

23 hours ago, Hunter259 said:

You didn't code it to print anything.

what

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, Runelight said:

what

I have no idea what you are trying to do but that doesn't print anything in its current form.

Main Gaming PC - i9 10850k @ 5GHz - EVGA XC Ultra 2080ti with Heatkiller 4 - Asrock Z490 Taichi - Corsair H115i - 32GB GSkill Ripjaws V 3600 CL16 OC'd to 3733 - HX850i - Samsung NVME 256GB SSD - Samsung 3.2TB PCIe 8x Enterprise NVMe - Toshiba 3TB 7200RPM HD - Lian Li Air

 

Proxmox Server - i7 8700k @ 4.5Ghz - 32GB EVGA 3000 CL15 OC'd to 3200 - Asus Strix Z370-E Gaming - Oracle F80 800GB Enterprise SSD, LSI SAS running 3 4TB and 2 6TB (Both Raid Z0), Samsung 840Pro 120GB - Phanteks Enthoo Pro

 

Super Server - i9 7980Xe @ 4.5GHz - 64GB 3200MHz Cl16 - Asrock X299 Professional - Nvidia Telsa K20 -Sandisk 512GB Enterprise SATA SSD, 128GB Seagate SATA SSD, 1.5TB WD Green (Over 9 years of power on time) - Phanteks Enthoo Pro 2

 

Laptop - 2019 Macbook Pro 16" - i7 - 16GB - 512GB - 5500M 8GB - Thermal Pads and Graphite Tape modded

 

Smart Phones - iPhone X - 64GB, AT&T, iOS 13.3 iPhone 6 : 16gb, AT&T, iOS 12 iPhone 4 : 16gb, AT&T Go Phone, iOS 7.1.1 Jailbroken. iPhone 3G : 8gb, AT&T Go Phone, iOS 4.2.1 Jailbroken.

 

Link to comment
Share on other sites

Link to post
Share on other sites

23 hours ago, Hunter259 said:

I have no idea what you are trying to do but that doesn't print anything in its current form.

i mean would it show college=200 and all and also gets initailized by that value of 200

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Runelight said:

i mean would it show college=200 and all and also gets initailized by that value of 200

It just sets either college or hostel to 200.

Main Gaming PC - i9 10850k @ 5GHz - EVGA XC Ultra 2080ti with Heatkiller 4 - Asrock Z490 Taichi - Corsair H115i - 32GB GSkill Ripjaws V 3600 CL16 OC'd to 3733 - HX850i - Samsung NVME 256GB SSD - Samsung 3.2TB PCIe 8x Enterprise NVMe - Toshiba 3TB 7200RPM HD - Lian Li Air

 

Proxmox Server - i7 8700k @ 4.5Ghz - 32GB EVGA 3000 CL15 OC'd to 3200 - Asus Strix Z370-E Gaming - Oracle F80 800GB Enterprise SSD, LSI SAS running 3 4TB and 2 6TB (Both Raid Z0), Samsung 840Pro 120GB - Phanteks Enthoo Pro

 

Super Server - i9 7980Xe @ 4.5GHz - 64GB 3200MHz Cl16 - Asrock X299 Professional - Nvidia Telsa K20 -Sandisk 512GB Enterprise SATA SSD, 128GB Seagate SATA SSD, 1.5TB WD Green (Over 9 years of power on time) - Phanteks Enthoo Pro 2

 

Laptop - 2019 Macbook Pro 16" - i7 - 16GB - 512GB - 5500M 8GB - Thermal Pads and Graphite Tape modded

 

Smart Phones - iPhone X - 64GB, AT&T, iOS 13.3 iPhone 6 : 16gb, AT&T, iOS 12 iPhone 4 : 16gb, AT&T Go Phone, iOS 7.1.1 Jailbroken. iPhone 3G : 8gb, AT&T Go Phone, iOS 4.2.1 Jailbroken.

 

Link to comment
Share on other sites

Link to post
Share on other sites

23 hours ago, Hunter259 said:

It just sets either college or hostel to 200.

so what should i do to print it ??? how can i use cout after that

Link to comment
Share on other sites

Link to post
Share on other sites

Okay, I don't know if your teacher is letting you get away with this stuff but if he is he should be shot. READ TIME OVER WRITE TIME!!!! If you have to take extra time to write it so some one can read it easily then so be it. You need to code with the idea in the back of your mind that someone somewhere has to look over this and it needs to be as clear and concise as possible. That being said, 1 initialization per line, initialize something before you use it.

 

cout << "Enter either type A or type B: " ;

char type = ' ';

cin >> type;

 

string college = "College";

string hostel = "a Hostel";

int amount = 200;

 

cout << "The student is going to " << type == A ? college : hostel << " with $" << amount  << "."<< endl;

 

If type is A this will output :

"The student is going to college with $200.

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, Runelight said:

so what should i do to print it ??? how can i use cout after that

You cout what you want? College or Hostel.

Main Gaming PC - i9 10850k @ 5GHz - EVGA XC Ultra 2080ti with Heatkiller 4 - Asrock Z490 Taichi - Corsair H115i - 32GB GSkill Ripjaws V 3600 CL16 OC'd to 3733 - HX850i - Samsung NVME 256GB SSD - Samsung 3.2TB PCIe 8x Enterprise NVMe - Toshiba 3TB 7200RPM HD - Lian Li Air

 

Proxmox Server - i7 8700k @ 4.5Ghz - 32GB EVGA 3000 CL15 OC'd to 3200 - Asus Strix Z370-E Gaming - Oracle F80 800GB Enterprise SSD, LSI SAS running 3 4TB and 2 6TB (Both Raid Z0), Samsung 840Pro 120GB - Phanteks Enthoo Pro

 

Super Server - i9 7980Xe @ 4.5GHz - 64GB 3200MHz Cl16 - Asrock X299 Professional - Nvidia Telsa K20 -Sandisk 512GB Enterprise SATA SSD, 128GB Seagate SATA SSD, 1.5TB WD Green (Over 9 years of power on time) - Phanteks Enthoo Pro 2

 

Laptop - 2019 Macbook Pro 16" - i7 - 16GB - 512GB - 5500M 8GB - Thermal Pads and Graphite Tape modded

 

Smart Phones - iPhone X - 64GB, AT&T, iOS 13.3 iPhone 6 : 16gb, AT&T, iOS 12 iPhone 4 : 16gb, AT&T Go Phone, iOS 7.1.1 Jailbroken. iPhone 3G : 8gb, AT&T Go Phone, iOS 4.2.1 Jailbroken.

 

Link to comment
Share on other sites

Link to post
Share on other sites

On 8/11/2016 at 10:27 PM, Hunter259 said:

You cout what you want? College or Hostel.

Well that is for the user to decide

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Runelight said:

Well that is for the user to decide

Then print that? 

Main Gaming PC - i9 10850k @ 5GHz - EVGA XC Ultra 2080ti with Heatkiller 4 - Asrock Z490 Taichi - Corsair H115i - 32GB GSkill Ripjaws V 3600 CL16 OC'd to 3733 - HX850i - Samsung NVME 256GB SSD - Samsung 3.2TB PCIe 8x Enterprise NVMe - Toshiba 3TB 7200RPM HD - Lian Li Air

 

Proxmox Server - i7 8700k @ 4.5Ghz - 32GB EVGA 3000 CL15 OC'd to 3200 - Asus Strix Z370-E Gaming - Oracle F80 800GB Enterprise SSD, LSI SAS running 3 4TB and 2 6TB (Both Raid Z0), Samsung 840Pro 120GB - Phanteks Enthoo Pro

 

Super Server - i9 7980Xe @ 4.5GHz - 64GB 3200MHz Cl16 - Asrock X299 Professional - Nvidia Telsa K20 -Sandisk 512GB Enterprise SATA SSD, 128GB Seagate SATA SSD, 1.5TB WD Green (Over 9 years of power on time) - Phanteks Enthoo Pro 2

 

Laptop - 2019 Macbook Pro 16" - i7 - 16GB - 512GB - 5500M 8GB - Thermal Pads and Graphite Tape modded

 

Smart Phones - iPhone X - 64GB, AT&T, iOS 13.3 iPhone 6 : 16gb, AT&T, iOS 12 iPhone 4 : 16gb, AT&T Go Phone, iOS 7.1.1 Jailbroken. iPhone 3G : 8gb, AT&T Go Phone, iOS 4.2.1 Jailbroken.

 

Link to comment
Share on other sites

Link to post
Share on other sites

On 8/11/2016 at 10:30 PM, Hunter259 said:

Then print that? 

Dude , I figured it out by myself .

{

char type ;

int college , hostel ;

cout<<"Enter the student type A or B"<<"\n" ;

cin>>type ;

(type==A)?cout<<"College account="<<college=200<<"\n" : cout<<"Hostel account"<<hostel=200<<"\n" ;

getch() ;

}

 

Thanks bros for ur help

Link to comment
Share on other sites

Link to post
Share on other sites

4 hours ago, Runelight said:

Dude , I figured it out by myself .

{

char type ;

int college , hostel ;

cout<<"Enter the student type A or B"<<"\n" ;

cin>>type ;

(type==A)?cout<<"College account="<<college=200<<"\n" : cout<<"Hostel account"<<hostel=200<<"\n" ;

getch() ;

}

 

Thanks bros for ur help

Just an FYI because I think it's worse then pointless learning things wrong:

If you write code like that in the real world your boss, maintainer, colleagues will skin you alive and rightfully so.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×