C
C#2y ago
daniel1

❔ how do i attach strings to integers and how do i use strings in while

.
44 Replies
daniel1
daniel1OP2y ago
A daily newspaper wants to increase its number of subscribers, and is launching a gift sale for new subscribers. subscription Newcomers over 50 will receive gift vouchers, and every other subscriber will receive a book. Write a program that will record the name and age of each new subscriber. The program will print the name of each new subscriber, and the gift he is entitled to. The program will end when "SOF" is entered for the new subscriber's name. i have tried to do the following and i dont know how to fix it
Pobiega
Pobiega2y ago
show us your attempt
daniel1
daniel1OP2y ago
string name; int age; Console.WriteLine("enter name"); name = Console.ReadLine(); while (name == sof)
Pobiega
Pobiega2y ago
sof? ah
daniel1
daniel1OP2y ago
do i need to put sof " " in these ?
Pobiega
Pobiega2y ago
well yes, otherwise C# thinks its a variable
daniel1
daniel1OP2y ago
oh
Pobiega
Pobiega2y ago
and the text you pasted above uses "SOF", not "sof"
daniel1
daniel1OP2y ago
btw did you help me before ?
Pobiega
Pobiega2y ago
maybe? I help a lot of people.
daniel1
daniel1OP2y ago
static void Main(string[] args) { string name; int age; Console.WriteLine("enter name"); name = Console.ReadLine(); while (name == "sof") { Console.WriteLine("enter age"); age = int.Parse(Console.ReadLine()); if (age > 50) { Console.WriteLine(name + "you are going to get a voucher"); } else { Console.WriteLine(name + "you shall recive a book"); } } } } } this is my current program but when i try to run it after i enetered my name it did not work is it beacuse i used the wrong stuff inside of while ? basicaly what i am trying to say is how do i make the program stop after entering the words sof
Pobiega
Pobiega2y ago
can you tell me what while (name == "sof") does?
daniel1
daniel1OP2y ago
i guss it does the oppistoe of what i wanted
Pobiega
Pobiega2y ago
yes
daniel1
daniel1OP2y ago
what i am asking is what am i supposed to put insted of == so that the program will work
Pobiega
Pobiega2y ago
==is the "equals" comparison operator do you not know what the "not equals" operator is?
daniel1
daniel1OP2y ago
ill be honest i havent coded in 3 months so i dont rember what it is
Pobiega
Pobiega2y ago
perhaps google knows? this is the very very basics
daniel1
daniel1OP2y ago
i tried to type it in i just didnt know how to look it up on google thats all thx ive got a problem when i enter the program i can only enter the name once and it dosent ask for the name agien but if i try and put the name inside it dosent work ethir
Pobiega
Pobiega2y ago
and why do you think that is?
daniel1
daniel1OP2y ago
all i know is that i am doing some thing wrong and its realeted to this name = Console.ReadLine(); while (name != "sof") as ive said i tried to put it inside while but that does not work i tried to put it outside but that dosent work you dont have to give me the whole answer just give me a hint
Pobiega
Pobiega2y ago
how many times are you asking the user to give their name?
daniel1
daniel1OP2y ago
once
Pobiega
Pobiega2y ago
yes, and is that what you want?
daniel1
daniel1OP2y ago
i want to ask them multiplie times i dont know how but it needs to be inside the while loop A daily newspaper wants to increase its number of subscribers, and is launching a gift sale for new subscribers. subscription Newcomers over 50 will receive gift vouchers, and every other subscriber will receive a book. Write a program that will record the name and age of each new subscriber. The program will print the name of each new subscriber, and the gift he is entitled to. The program will end when "SOF" is entered for the new subscriber's name.\ thats the task at hand
Pobiega
Pobiega2y ago
so put it inside the loop
daniel1
daniel1OP2y ago
yeah but its giving me a red x
Pobiega
Pobiega2y ago
and if you read the error message?
daniel1
daniel1OP2y ago
use of unasinged local verabile "name" and if i put it in the loop and luanch it the same thing happens
Pobiega
Pobiega2y ago
can we perhaps assign a value to the name both outside and inside the loop?
daniel1
daniel1OP2y ago
ive tried that just now the problem is it overlooks the first name man my english is terrible right now
Pobiega
Pobiega2y ago
what if we assigned a fixed value, that we know is not "SOF"? like, null, or ""
daniel1
daniel1OP2y ago
whats null ? the point is i am asked to recive each name and recive the age and print out each name and tell them what they got
Pobiega
Pobiega2y ago
I get that. I don't really get the feeling that you are trying very hard here thou.
daniel1
daniel1OP2y ago
man i printed out the whole thing all i am asking you is how do i perfect it i am not good with strings and i havent coded in 3 months
Pobiega
Pobiega2y ago
I'm not going to code it for you, not entirely but also not piece by piece What is the current problem?
daniel1
daniel1OP2y ago
the first name you enter gets overlooked and i do not know how to fix it
Pobiega
Pobiega2y ago
show your code
daniel1
daniel1OP2y ago
wait what if i name two names ah nah right i will send the code string name; int age; Console.WriteLine("enter name"); name = Console.ReadLine(); while (name != "sof") { Console.WriteLine("enter name"); name = Console.ReadLine(); Console.WriteLine("enter age"); age = int.Parse(Console.ReadLine()); if (age > 50) { Console.WriteLine(name + " you are going to get a voucher"); } else { Console.WriteLine(name + " you shall recive a book"); }
Pobiega
Pobiega2y ago
well you ask for the name, then you immediately again ask for the name
daniel1
daniel1OP2y ago
if i dont ask for the name at the start then the program dosent work if i dont ask for the name inside the loop there will only be one name
Pobiega
Pobiega2y ago
is asking the user the ONLY way to make a string in C#?
daniel1
daniel1OP2y ago
thenk you very much string name="dan"; int age;
while (name != "sof") { Console.WriteLine("enter name"); name = Console.ReadLine(); Console.WriteLine("enter age"); age = int.Parse(Console.ReadLine()); if (age > 50) { Console.WriteLine(name + " you are going to get a voucher"); } else { Console.WriteLine(name + " you shall recive a book"); }
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server