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

Ddaniel12/27/2023
.
Ddaniel12/27/2023
A daily newspaper wants to increase its number of subscribers, and is launching a gift sale for new subscribers. subscription
Ddaniel12/27/2023
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.
Ddaniel12/27/2023
i have tried to do the following and i dont know how to fix it
PPobiega2/27/2023
show us your attempt
Ddaniel12/27/2023
string name;
int age;
Console.WriteLine("enter name");
name = Console.ReadLine();
while (name == sof)
PPobiega2/27/2023
sof?
PPobiega2/27/2023
ah
Ddaniel12/27/2023
do i need to put sof " " in these ?
PPobiega2/27/2023
well yes, otherwise C# thinks its a variable
Ddaniel12/27/2023
oh
PPobiega2/27/2023
and the text you pasted above uses "SOF", not "sof"
Ddaniel12/27/2023
btw did you help me before ?
PPobiega2/27/2023
maybe? I help a lot of people.
Ddaniel12/27/2023
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");
}

}
}
}
}
Ddaniel12/27/2023
this is my current program
Ddaniel12/27/2023
but when i try to run it
Ddaniel12/27/2023
after i enetered my name it did not work
Ddaniel12/27/2023
is it beacuse i used the wrong stuff inside of while ?
Ddaniel12/27/2023
basicaly
Ddaniel12/27/2023
what i am trying to say is
Ddaniel12/27/2023
how do i make the program stop after entering the words sof
PPobiega2/27/2023
can you tell me what while (name == "sof") does?
Ddaniel12/27/2023
i guss it does the oppistoe of what i wanted
PPobiega2/27/2023
yes
Ddaniel12/27/2023
what i am asking is what am i supposed to put insted of == so that the program will work
PPobiega2/27/2023
==is the "equals" comparison operator
PPobiega2/27/2023
do you not know what the "not equals" operator is?
Ddaniel12/27/2023
ill be honest i havent coded in 3 months so i dont rember what it is
PPobiega2/27/2023
perhaps google knows?
PPobiega2/27/2023
this is the very very basics
Ddaniel12/27/2023
i tried to type it in i just didnt know how to look it up on google
Ddaniel12/27/2023
thats all
Ddaniel12/27/2023
thx
Ddaniel12/27/2023
ive got a problem
Ddaniel12/27/2023
when i enter the program
Ddaniel12/27/2023
i can only enter the name once
Ddaniel12/27/2023
and it dosent ask for the name agien
Ddaniel12/27/2023
but if i try and put the name inside it dosent work ethir
PPobiega2/27/2023
and why do you think that is?
Ddaniel12/27/2023
all i know is that i am doing some thing wrong and
Ddaniel12/27/2023
its realeted to this
Ddaniel12/27/2023
name = Console.ReadLine();
while (name != "sof")
Ddaniel12/27/2023
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
Ddaniel12/27/2023
you dont have to give me the whole answer just give me a hint
PPobiega2/27/2023
how many times are you asking the user to give their name?
Ddaniel12/27/2023
once
PPobiega2/27/2023
yes, and is that what you want?
Ddaniel12/27/2023
i want to ask them multiplie times
Ddaniel12/27/2023
i dont know how but it needs to be inside the while loop
Ddaniel12/27/2023
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.\
Ddaniel12/27/2023
thats the task at hand
PPobiega2/27/2023
so put it inside the loop
Ddaniel12/27/2023
yeah but its giving me a red x
PPobiega2/27/2023
and if you read the error message?
Ddaniel12/27/2023
use of unasinged local verabile "name"
Ddaniel12/27/2023
and if i put it in the loop and luanch it the same thing happens
PPobiega2/27/2023
can we perhaps assign a value to the name both outside and inside the loop?
Ddaniel12/27/2023
ive tried that just now
Ddaniel12/27/2023
the problem is it overlooks the first name
Ddaniel12/27/2023
man my english is terrible right now
PPobiega2/27/2023
what if we assigned a fixed value, that we know is not "SOF"?
PPobiega2/27/2023
like, null, or ""
Ddaniel12/27/2023
whats null ?
Ddaniel12/27/2023
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
PPobiega2/27/2023
I get that.
PPobiega2/27/2023
I don't really get the feeling that you are trying very hard here thou.
Ddaniel12/27/2023
man
Ddaniel12/27/2023
i printed out the whole thing all i am asking you is how do i perfect it
Ddaniel12/27/2023
i am not good with strings
Ddaniel12/27/2023
and i havent coded in 3 months
PPobiega2/27/2023
I'm not going to code it for you, not entirely but also not piece by piece
PPobiega2/27/2023
What is the current problem?
Ddaniel12/27/2023
the first name you enter gets overlooked
Ddaniel12/27/2023
and i do not know how to fix it
PPobiega2/27/2023
show your code
Ddaniel12/27/2023
wait
Ddaniel12/27/2023
what if i name two names
Ddaniel12/27/2023
ah nah
Ddaniel12/27/2023
right i will send the code
Ddaniel12/27/2023
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");
}
PPobiega2/27/2023
well you ask for the name, then you immediately again ask for the name
Ddaniel12/27/2023
if i dont ask for the name at the start
Ddaniel12/27/2023
then the program dosent work
Ddaniel12/27/2023
if i dont ask for the name inside the loop there will only be one name
PPobiega2/27/2023
is asking the user the ONLY way to make a string in C#?
Ddaniel12/27/2023
thenk you very much
Ddaniel12/27/2023
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");
}
AAccord2/28/2023
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.