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");

 

Hey guys , I got Homework in C++ and got to do it . Please help me from getting punished guys . Immediate help is required . The Problem is ,

Write a C++ program to input a student type A or B . If the student type is A , then initialize the college account with 200$ , otherwise initialise the hostel account with 200$ .

 

Please guys I need the code for the program,immediately . I hope u will help thanks in advance guys ;) 

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, Runelight said:

Hey guys , I got Homework in C++ and got to do it .

That's generally the intention behind homework... you have to do it. Yourself.

1 minute ago, Runelight said:

Please guys I need the code for the program,immediately .

No. At least make the effort yourself. Your laziness is not our problem.

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
Share on other sites

Link to post
Share on other sites

On 8/11/2016 at 9:29 PM, Nuluvius said:

That's generally the intention behind homework... you have to do it. Yourself.

No. At least make the effort yourself. Your laziness is not our problem.

Well I am like the best programer in class or at least thats what teachers says . But Im having trouble with this one . And cannot , derive an expresion for it . I cannot if else if . That is forbidden by the teacher . Instead I have to do it with conditional operators which are C++ Exclusive . Im having trouble in this one and one more

 

EDIT : I am also allowed to use the C++ exclusive Logical operators

Edited by Runelight
Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Runelight said:

Well I am like the best programer in class or at least thats what teachers says . But Im having trouble with this one . And cannot , derive an expresion for it . I cannot if else if . That is forbidden by the teacher . Instead I have to do it with conditional operators which are C++ Exclusive . Im having trouble in this one and one more

Welcome to learning. Try it sometime. This is so simple.

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:

Welcome to learning. Try it sometime. This is so simple.

Man I seriously need to get the answer . I tryed every thing known to me . Yet I cant do it . My mother knows programing but only in C and not C++ .So I thought I will get help here . Anyone please help me

Link to comment
Share on other sites

Link to post
Share on other sites

The conditional operator (also called ternary operator) is not exclusive to C++, some other languages also have it (just fyi). It's basically just another way to write an if/else statement. Take a look at this tutorial page for them.

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

23 hours ago, madknight3 said:

The conditional operator (also called ternary operator) is not exclusive to C++. It's basically just another way to write an if/else statement. Take a look at this tutorial page for them.

 

 

Man I know what ternary operators are . All I want is the code which i dont seem to understand that particular one

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Runelight said:

Man I seriously need to get the answer . I tryed every thing known to me . Yet I cant do it . My mother knows programing but only in C and not C++ .So I thought I will get help here . Anyone please help me

It's just an If else statement with a read in. How are you out of ideas.

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's just an If else statement with a read in. How are you out of ideas.

But I cant use If else statement u c . If I was allowed I would have done it . But this is new to me and just dont seem to get it

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Runelight said:

But I cant use If else statement u c . If I was allowed I would have done it . But this is new to me and just dont seem to get it

Then use a ternary as someone else said.

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

1 minute ago, Runelight said:

Man I know what ternary operators are . All I want is the code which i dont seem to understand that particular one

How about you post the code you've tried and we can point out what you're doing wrong.

Link to comment
Share on other sites

Link to post
Share on other sites

23 hours ago, madknight3 said:

How about you post the code you've tried and we can point out what you're doing wrong.

Well man I need to write the code and Im not getting that code . 

 

23 hours ago, Hunter259 said:

Then use a ternary as someone else said.

But how should I use it ???

could u please list the formula code and what type the variables used are

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Runelight said:

Well man I need to write the code and Im not getting that code . 

 

But how should I use it ???

could u please list the formula code and what type the variables used are

You are being way to lazy. We aren't just going to give you the answer.

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 are being way to lazy. We aren't just going to give you the answer.

please man I need it and if i know the code , i would have written . please man please help me . I have  formula in mind . But I dont understand how to use that.

 

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, Runelight said:

please man I need it and if i know the code , i would have written . please man please help me . I have  formula in mind . But I dont understand how to use that.

 

https://en.wikipedia.org/wiki/%3F:#C.2B.2B

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 9:46 PM, Hunter259 said:

I dont understand whats written in wikipedia . Well the code I have is

 

 

char A , B ;

int college , hostel ;

cout <<"Enter student type A or B" ;

(A:B) ? college==200 : hostel==200 ;

 

is this correct ??? please reply

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Runelight said:

I dont understand whats written in wikipedia . Well the code I have is

 

 

char A , B ;

int college , hostel ;

cout <<"Enter student type A or B" ;

(A:B) ? college==200 : hostel==200 ;

 

is this correct ??? please reply

First : Why do you have two read in variables when you only need one?

Second : You aren't setting those variables equal to anything. You are just checking if they are equal to 200.

Third : Did you read that page? 

(argc > 1 ? a : b) = 1;

Your variable, your operator, your A answer. Then the turinary, if greater than the requirement for A set A = 1, else set B = 1. 

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 9:54 PM, Hunter259 said:

First : Why do you have two read in variables when you only need one?

Second : You aren't setting those variables equal to anything. You are just checking if they are equal to 200.

Third : Did you read that page? 


(argc > 1 ? a : b) = 1;

Your variable, your operator, your A answer. Then the turinary, if greater than the requirement for A set A = 1, else set B = 1. 

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

Link to comment
Share on other sites

Link to post
Share on other sites

Copied from the wiki page:

Quote
condition ? value_if_true : value_if_false

 

Desktop: Intel i9-10850K (R9 3900X died 😢 )| MSI Z490 Tomahawk | RTX 2080 (borrowed from work) - MSI GTX 1080 | 64GB 3600MHz CL16 memory | Corsair H100i (NF-F12 fans) | Samsung 970 EVO 512GB | Intel 665p 2TB | Samsung 830 256GB| 3TB HDD | Corsair 450D | Corsair RM550x | MG279Q

Laptop: Surface Pro 7 (i5, 16GB RAM, 256GB SSD)

Console: PlayStation 4 Pro

Link to comment
Share on other sites

Link to post
Share on other sites

23 hours ago, mathijs727 said:

Copied from the wiki page:

 

well that I know if conition is true the first expression will evaluate otherwise the 2nd will evaluate . but I dont clearly understand how to use it . Im using c++  for the first time this year 

Link to comment
Share on other sites

Link to post
Share on other sites

What about this one  ,

 

char type ;

int college , hostel ;

cin>>type ;

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

 

Link to comment
Share on other sites

Link to post
Share on other sites

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");

 

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

2 minutes ago, Runelight said:

What about this one  ,

 

char type ;

int college , hostel ;

cin>>type ;

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

 

Tada. You learned.

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 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");

 

dude i cannot use if else if statements ok

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Runelight said:

dude i cannot use if else if statements ok

Omg. Why do you think there is a giant OR.

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

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

×