44 Replies
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
show us your attempt
string name;
int age;
Console.WriteLine("enter name");
name = Console.ReadLine();
while (name == sof)
sof
?
ahdo i need to put sof " " in these ?
well yes, otherwise C# thinks its a variable
oh
and the text you pasted above uses "SOF", not "sof"
btw did you help me before ?
maybe? I help a lot of people.
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
can you tell me what
while (name == "sof")
does?i guss it does the oppistoe of what i wanted
yes
what i am asking is what am i supposed to put insted of == so that the program will work
==
is the "equals" comparison operator
do you not know what the "not equals" operator is?ill be honest i havent coded in 3 months so i dont rember what it is
perhaps google knows?
this is the very very basics
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
and why do you think that is?
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
how many times are you asking the user to give their name?
once
yes, and is that what you want?
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
so put it inside the loop
yeah but its giving me a red x
and if you read the error message?
use of unasinged local verabile "name"
and if i put it in the loop and luanch it the same thing happens
can we perhaps assign a value to the name both outside and inside the loop?
ive tried that just now
the problem is it overlooks the first name
man my english is terrible right now
what if we assigned a fixed value, that we know is not "SOF"?
like, null, or ""
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
I get that.
I don't really get the feeling that you are trying very hard here thou.
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
I'm not going to code it for you, not entirely but also not piece by piece
What is the current problem?
the first name you enter gets overlooked
and i do not know how to fix it
show your code
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");
}
well you ask for the name, then you immediately again ask for the name
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
is asking the user the ONLY way to make a string in C#?
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"); }
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"); }
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.