Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,652 members, 7,809,467 topics. Date: Friday, 26 April 2024 at 10:06 AM

C++ Beginner Discussion Room: Drop Your Codes - Programming (3) - Nairaland

Nairaland Forum / Science/Technology / Programming / C++ Beginner Discussion Room: Drop Your Codes (11648 Views)

I Want To Hire A Beginner Who Is Willing To Learn New Skills / Special Codes To Format Text On Nairaland / Should A Beginner Learn 2 Programming Languages At Once? (2) (3) (4)

(1) (2) (3) (4) (5) (Reply) (Go Down)

Re: C++ Beginner Discussion Room: Drop Your Codes by adelolaa(m): 11:38pm On Dec 14, 2013
raynold: wrote this program in c and its working perfectly, just wrote this now in c++..

#include<iostream>

using namespace std;
int main()
{
int a, b, c, num;
int choice;
cout<< "\t\t\t welcom choose your operation\n";
for ( num = 1; num <= 7; num++)
{
cout<< "\t\t\t -1 addition\n \t\t\t -2 substraction\n \t\t\t -3 multipication\n";
cout<< "\t\t\t -4 exit\n ";
cin>> choice;
if (choice == 1)
{
cout<< "enter first value :";
cin>> a;
cout<< "enter second value :";
cin>> b;
c = a+b;
cout<< " addition is" << c<<endln;
}
if (choice == 2)
{
cout<< "enter first value :";
cin >> a;
cout<< "enter second value :";
cin >> b;
c = a - b;
cout<< " the subtraction is << c<<endln;
}
if (choice == 3)
{
cout<< "enter first value :";
cin>> a;
cout<< "enter second value :";
cin>> b;
c = a * b;
cout<< " the multiplication is << c<<endln;
}
if (choice == 4)
{
cout<< "\t\t\t thanks for using mini calcultor bye\n";
break;
}
if ( choice >= 5)
{
cout<< "\t\t\t invalid choice try again\n";
}
}
}


there is so many error in ur codes. av corrected it though . eg. nothing like endln and u forgot to put end ( " ) quote for some string.





here is d corrected one



#include<iostream>
using namespace std;
int main()
{
int a, b, c, num;
int choice;
cout<< "\t\t\t welcom choose your operation\n";
for ( num = 1; num <= 7; num++)
{
cout<< "\t\t\t -1 addition\n \t\t\t -2 substraction\n \t\t\t -3 multipication\n";
cout<< "\t\t\t -4 exit\n ";
cin>> choice;
if (choice == 1)
{
cout<< "enter first value :";
cin>> a;
cout<< "enter second value :";
cin>> b;
c = a+b;
cout<< " addition is" << c<<endl;
}
if (choice == 2)
{
cout<< "enter first value :";
cin >> a;
cout<< "enter second value :";
cin >> b;
c = a - b;
cout<< " the subtraction is" << c<<endl;
}
if (choice == 3)
{
cout<< "enter first value :";
cin>> a;
cout<< "enter second value :";
cin>> b;
c = a * b;
cout<< " the multiplication is" << c<<endl;
}
if (choice == 4)
{
cout<< "\t\t\t thanks for using mini calcultor bye\n";
break;
}
if ( choice >= 5)
{
cout<< "\t\t\t invalid choice try again\n";
}
}
}
Re: C++ Beginner Discussion Room: Drop Your Codes by adelolaa(m): 6:38am On Dec 15, 2013
join me to solve this seven questions this week



Assignment for chapter five (while loop, for loop, do-while loop)

HOD: ALEX ALLAIN

STUDENT: XARMZON

COURSE: JUMPING INTO C++


Q1: write a program that prints out then entire lyrics to a full rendition of "99 bottles of beer"

Q2: write a menu program that let the user select from a list of options, and if the input is not one of the options, reprint the list.

Q3: write a program that compute a running sum of inputs from the user, terminate when the gives an input of zero (0)

Q4: write a password prompt that give a user only a certain number of password entry attempts, so that the user cannot easily write a password cracker.

Q5: try writing each practise problem with each kind of loop, notice which loops work well for each kind problem.

Q6: write a program that displays first 20 square numbers.

Q7: write a program that provides the option tallying up the result of a poll with 3 possible values. First input to the program is the poll question; the next three input are the possible answers. The first answer is indicated by 1, the second by 2, the third by 3, the answers are tailed until a zero (0) is entered. The program should then show the results of the poll try making a bar graph that show the results properly scale to fit on your screen no matter how many results were entered.

Good luck!
Re: C++ Beginner Discussion Room: Drop Your Codes by raynold(m): 7:00am On Dec 15, 2013
adelolaa:


there is so many error in ur codes. av corrected it though . eg. nothing like endln and u forgot to put end ( " ) quote for some string.





here is d corrected one



#include<iostream>
using namespace std;
int main()
{
int a, b, c, num;
int choice;
cout<< "\t\t\t welcom choose your operation\n";
for ( num = 1; num <= 7; num++)
{
cout<< "\t\t\t -1 addition\n \t\t\t -2 substraction\n \t\t\t -3 multipication\n";
cout<< "\t\t\t -4 exit\n ";
cin>> choice;
if (choice == 1)
{
cout<< "enter first value :";
cin>> a;
cout<< "enter second value :";
cin>> b;
c = a+b;
cout<< " addition is" << c<<endl;
}
if (choice == 2)
{
cout<< "enter first value :";
cin >> a;
cout<< "enter second value :";
cin >> b;
c = a - b;
cout<< " the subtraction is" << c<<endl;
}
if (choice == 3)
{
cout<< "enter first value :";
cin>> a;
cout<< "enter second value :";
cin>> b;
c = a * b;
cout<< " the multiplication is" << c<<endl;
}
if (choice == 4)
{
cout<< "\t\t\t thanks for using mini calcultor bye\n";
break;
}
if ( choice >= 5)
{
cout<< "\t\t\t invalid choice try again\n";
}
}
}
thanks bro..
Re: C++ Beginner Discussion Room: Drop Your Codes by raynold(m): 7:03am On Dec 15, 2013
adelolaa: join me to solve this seven questions this week



Assignment for chapter five (while loop, for loop, do-while loop)

HOD: ALEX ALLAIN

STUDENT: XARMZON

COURSE: JUMPING INTO C++


Q1: write a program that prints out then entire lyrics to a full rendition of "99 bottles of beer"

Q2: write a menu program that let the user select from a list of options, and if the input is not one of the options, reprint the list.

Q3: write a program that compute a running sum of inputs from the user, terminate when the gives an input of zero (0)

Q4: write a password prompt that give a user only a certain number of password entry attempts, so that the user cannot easily write a password cracker.

Q5: try writing each practise problem with each kind of loop, notice which loops work well for each kind problem.

Q6: write a program that displays first 20 square numbers.

Q7: write a program that provides the option tallying up the result of a poll with 3 possible values. First input to the program is the poll question; the next three input are the possible answers. The first answer is indicated by 1, the second by 2, the third by 3, the answers are tailed until a zero (0) is entered. The program should then show the results of the poll try making a bar graph that show the results properly scale to fit on your screen no matter how many results were entered.

Good luck!!!!!!

I'll start 1 and 2 this morning
Re: C++ Beginner Discussion Room: Drop Your Codes by raynold(m): 7:10am On Dec 15, 2013
here is number 4 in c, I wrote it I think 3 days back.. I'll post in c++ later


#include <stdio.h>
main()
{
int password;
int num;
for ( num =1; num <=3; num++)
{
printf (" \t\t\t\v\v please enter password : " );
scanf ("%d",&password);
if (password == 1234)
{
printf (" \t\t\t\v\v login successful\n" );
break;
}
if (password != 1234)
{
printf ( " \t\t\t\v\v incorect password TRY AGAIN!\n" );
}
if ( num == 2)
{
printf ("\t\t\t\v\vWARNING:: you have one(1) last attem\n\t\t\t\t\n" );
}
if (num == 3)
{
printf ("\t\t\t \v\vsorry you entered wrong passwords\n \t\t\tin all three attempts\n" );
}
}
}

1 Like

Re: C++ Beginner Discussion Room: Drop Your Codes by raynold(m): 7:18am On Dec 15, 2013
number 4 in c++
i really hope no errors in this one, my laptop is a bit faulty can't compile c++ for now

#include <iostream>
using namespace std;
main()
{
int password;
int num;
for ( num =1; num <=3; num++)
{
cout<< " \t\t\t\v\v please enter password : ";
cin>> password;
if (password == 1234)
{
cout<< " \t\t\t\v\v login successful\n";
break;
}
if (password != 1234)
{
cout<< " \t\t\t\v\v incorect password TRY AGAIN!\n";
}
if ( num == 2)
{
cout<< "\t\t\t\v\vWARNING:: you have one(1) last attem\n\t\t\t\t\n";
}
if (num == 3)
{
cout<< "\t\t\t \v\vsorry you entered wrong passwords\n \t\t\t in all three attempts\n";
}
}
}
Re: C++ Beginner Discussion Room: Drop Your Codes by raynold(m): 9:31am On Dec 15, 2013
answer to question 1 in c++
please note I've only compiled the program in c and its working well if any error kindly lemme know

#include <iostream>
using namespace std;
main()
{
int num;
int beer=0;
for( num =1; num <=99; num++)
{
beer++;
cout<< beer<< "bottles of beer\n";
}
}

answer to question number 1 in c
working fine


#include <stdio.h>
main()
{
int num;
int beer=0;
for( num =1; num <=99; num++)
{
beer++;
printf (" %d bottle of beer\n",beer);
}
}
Re: C++ Beginner Discussion Room: Drop Your Codes by raynold(m): 9:43am On Dec 15, 2013
number 1 in while loop for both c and c++


#include <stdio.h>
main()
{
int num=1;
int beer=0;
while (num <= 99)
{
num++;
beer++;
printf (" %d bottle of beer\n",beer);
}
}


in c++

#include <iostream>
main()
{
int num=1;
int beer=0;
while (num <= 99)
{
num++;
beer++;
cout<< beer<< "bottle of beer\n";
}
}
Re: C++ Beginner Discussion Room: Drop Your Codes by adelolaa(m): 11:03am On Dec 15, 2013
thank you all. I will post my solution to question 2 and 3 dis nite. question 1 and 4 is solve by u
Re: C++ Beginner Discussion Room: Drop Your Codes by raynold(m): 11:54am On Dec 15, 2013
adelolaa: thank you all. I will post my solution to question 2 and 3 dis nite. question 1 and 4 is solve by u
thanks mate.. really want to see how u did your number 3 and I don't understand question 6 and 7
Re: C++ Beginner Discussion Room: Drop Your Codes by wisemania(m): 12:14pm On Dec 15, 2013
@raynold, its better u just stick to one lang,if its c ,den let it be, if its cpp den let it be....coz i kw u wudnt like me to com here creating awearness dat i kw html,css,javascript,c,cpp....
I kud aswell ryt all d programs in js,c and cpp if i so wish,bt it wudnt be a good idea.....i beg!
Ur codes pure sha....nize wrk....
Re: C++ Beginner Discussion Room: Drop Your Codes by raynold(m): 12:31pm On Dec 15, 2013
wisemania: @raynold, its better u just stick to one lang,if its c ,den let it be, if its cpp den let it be....coz i kw u wudnt like me to com here creating awearness dat i kw html,css,javascript,c,cpp....
I kud aswell ryt all d programs in js,c and cpp if i so wish,bt it wudnt be a good idea.....i beg!
Ur codes pure sha....nize wrk....
lol.. not like that o, a guy posted he only knows C here so am just trying to like solve the questions for those that are only into c programming my guy no vex o.. I'll only post in c++ from now.. am actually planning to stick to one programing lang, don't knw which yet.. thanks trying my best..
Re: C++ Beginner Discussion Room: Drop Your Codes by wisemania(m): 12:42pm On Dec 15, 2013
//Soln in c to Q 6--Square program

#include <stdio.h>
#include <math.h> //include d math header file, so as to invoke d pow() function

#define TWENTY 20 // sybolic
constant
int main()
{

int num, counter;

printf("this program prints the squares of the first 20 numbers(0-19)\n"wink;

printf("numbers | squares\n"wink;

for (counter = 0, num = 0 ; counter < TWENTY; counter++, num++)
printf("%2d %12d\n", num, pow(num, 2));

return 0;
}

2 Likes

Re: C++ Beginner Discussion Room: Drop Your Codes by raynold(m): 2:36pm On Dec 15, 2013
wisemania: //Soln in c to Q 6--Square program

#include <stdio.h>
#include <math.h> //include d math header file, so as to invoke d pow() function

#define TWENTY 20 // sybolic
constant
int main()
{

int num, counter;

printf("this program prints the squares of the first 20 numbers(0-19)\n"wink;

printf("numbers | squares\n"wink;

for (counter = 0, num = 0 ; counter < TWENTY; counter++, num++)
printf("%2d %12d\n", num, pow(num, 2));

return 0;
}
nice.. any other to do this??
Re: C++ Beginner Discussion Room: Drop Your Codes by wisemania(m): 3:52pm On Dec 15, 2013
raynold: nice.. any other to do this??
sur boss...
U can remove:
#define TWENTY 20 from d program, and use just "20" 4ur test in d if stat...
And also d pow() function ...u sure can use just "num * num"
........
//Soln in C to Q 6--using a "do while " loop.

#include <stdio.h>
int main()
{
int num, i;
i = 0;
num = 0;
printf("numbers squares\n" );

do{
printf("%2d %10d", num, num * num) ;
i++, num++;
}
while (i < 20) ;
return 0;
}
Re: C++ Beginner Discussion Room: Drop Your Codes by adelolaa(m): 4:13pm On Dec 15, 2013
my q2 solution is ready but I need to fix so bugs their. coz I keep getting run time error.
Re: C++ Beginner Discussion Room: Drop Your Codes by raynold(m): 4:31pm On Dec 15, 2013
wisemania:
sur boss...
U can remove:
#define TWENTY 20 from d program, and use just "20" 4ur test in d if stat...
And also d pow() function ...u sure can use just "num * num"
........
//Soln in C to Q 6--using a "do while " loop.

#include <stdio.h>
int main()
{
int num, i;
i = 0;
num = 0;
printf("numbers squares\n" );

do{
printf("%2d %10d", num, num * num) ;
i++, num++;
}
while (i < 20) ;
return 0;
}
Re: C++ Beginner Discussion Room: Drop Your Codes by adelolaa(m): 10:41am On Dec 17, 2013
// solution to question 2 chapter five

//write a menu program that let the user
//select from a list of options, and if the
//input is not one of the options, reprint
//the list.

#include <iostream>
#include <string>
using namespace std;

int main()
{

string type = " ";

cout << "Welcome to xarm softdrinks shop" << endl << endl;

cout << "choose your order below! (a - n)" << endl << endl;
cout << "a - Coca-Cola \t\t b - Sprite" << endl;
cout << "c - Fanta \t\t d - Limca" << endl;
cout << "e - Mountain Dew \t f - Pepsi" << endl;
cout << "g - 7-Up \t\t h - Maltina" << endl;
cout << "i - Mirinda \t\t j - Malta Guiness \t" << endl;
cout << "k - Malt \t\t l - Amstel Malta \t" << endl;
cout << "m - maltina" << endl << endl;

cout << "Your order: ";

getline (cin, type);

while ((type != "a" ) || (type != "b" ) || (type != "c" ) || (type != "d" ) || (type != "e" ) || (type != "f" ) || (type != "g" ) || (type != "h" ) || (type != "i" ) || (type != "j" ) || (type != "k" ) || (type != "l" ) || (type != "m" ) )
{
cout << endl;

if ((type == "a" ) || (type == "b" ) || (type == "c" ) || (type == "d" ) || (type == "e" ) || (type == "f" ) || (type == "g" ) || (type == "h" ) || (type == "i" ) || (type == "j" ) || (type == "k" ) || (type == "l" ) || (type == "m" ) )

{

cout << "Thanks! i will order that for you!" << endl;
break;

}

cout << endl;

cout << "Invalid order! " << endl << endl;
cout << "Choose from a - m only " << endl << endl;

cout << "a - Coca-Cola \t\t b - Sprite" << endl;
cout << "c - Fanta \t\t d - Limca" << endl;
cout << "e - Mountain Dew \t f - Pepsi" << endl;
cout << "g - 7-Up \t\t h - Maltina" << endl;
cout << "i - Mirinda \t\t j - Malta Guiness \t" << endl;
cout << "k - Malt \t\t l - Amstel Malta \t" << endl;
cout << "m - maltina" << endl << endl;

cout << "Your order again: ";

cin >> type;



}

//done

}

bug fixed
Re: C++ Beginner Discussion Room: Drop Your Codes by adelolaa(m): 10:54am On Dec 17, 2013
screenshots

Re: C++ Beginner Discussion Room: Drop Your Codes by raynold(m): 12:35pm On Dec 17, 2013
adelolaa: // solution to question 2 chapter five

//write a menu program that let the user
//select from a list of options, and if the
//input is not one of the options, reprint
//the list.

#include <iostream>
#include <string>
using namespace std;

int main()
{

string type = " ";

cout << "Welcome to xarm softdrinks shop" << endl << endl;

cout << "choose your order below! (a - n)" << endl << endl;
cout << "a - Coca-Cola \t\t b - Sprite" << endl;
cout << "c - Fanta \t\t d - Limca" << endl;
cout << "e - Mountain Dew \t f - Pepsi" << endl;
cout << "g - 7-Up \t\t h - Maltina" << endl;
cout << "i - Mirinda \t\t j - Malta Guiness \t" << endl;
cout << "k - Malt \t\t l - Amstel Malta \t" << endl;
cout << "m - maltina" << endl << endl;

cout << "Your order: ";

getline (cin, type);

while ((type != "a" ) || (type != "b" ) || (type != "c" ) || (type != "d" ) || (type != "e" ) || (type != "f" ) || (type != "g" ) || (type != "h" ) || (type != "i" ) || (type != "j" ) || (type != "k" ) || (type != "l" ) || (type != "m" ) )
{
cout << endl;

if ((type == "a" ) || (type == "b" ) || (type == "c" ) || (type == "d" ) || (type == "e" ) || (type == "f" ) || (type == "g" ) || (type == "h" ) || (type == "i" ) || (type == "j" ) || (type == "k" ) || (type == "l" ) || (type == "m" ) )

{

cout << "Thanks! i will order that for you!" << endl;
break;

}

cout << endl;

cout << "Invalid order! " << endl << endl;
cout << "Choose from a - m only " << endl << endl;

cout << "a - Coca-Cola \t\t b - Sprite" << endl;
cout << "c - Fanta \t\t d - Limca" << endl;
cout << "e - Mountain Dew \t f - Pepsi" << endl;
cout << "g - 7-Up \t\t h - Maltina" << endl;
cout << "i - Mirinda \t\t j - Malta Guiness \t" << endl;
cout << "k - Malt \t\t l - Amstel Malta \t" << endl;
cout << "m - maltina" << endl << endl;

cout << "Your order again: ";

cin >> type;



}

//done

}

bug fixed
nice..
I'll try writting another
Re: C++ Beginner Discussion Room: Drop Your Codes by adelolaa(m): 1:40pm On Dec 17, 2013
raynold: nice..
I'll try writting another


thanks. I will drop solution to question 2 dis nite
Re: C++ Beginner Discussion Room: Drop Your Codes by adelolaa(m): 5:21pm On Dec 17, 2013
//solution to Q3 chapter 5

// write a program that compute a
// running sum of inputs from the user,
// terminate when the user gives an input
// of zero (0)


#include <iostream>
using namespace std;

int main()
{
long firstInput;
long secondInput;


cout << "Enter your numbers! (0 for both to quit)" << endl << endl;
cout << "First number ";
cin >> firstInput;
cout << "Second number " ;
cin >> secondInput;

cout << "the sum of the both numbers is " << firstInput + secondInput << endl;

while ((firstInput && secondInput) != 0)
{
if ((firstInput && secondInput) == 0 )
{
cout << "Thank you!" << endl;
break;
}

cout << "enter another numbers ( 0 for both to quit)" << endl;
cout << "First number: ";
cin >> firstInput;
cout << "Second number: ";
cin >> secondInput;
cout << "the sum of the numbers is " << firstInput + secondInput << endl;


}

//accomplished

}
Re: C++ Beginner Discussion Room: Drop Your Codes by raynold(m): 10:47am On Dec 18, 2013
i just finished writing this program in c
\\ restaurant menu program


#include<stdio.h>
#include<stdlib.h>

main()
{
int food;
int choice;
printf ("\t\t WELCOME TO AKPOS RESTAURANT\n" );
printf ("\t\t Menu for today\n" );

printf ("\t\t Enter category\n \t\t -1 Breakfast\n \t\t -2 lunch\n \t\t -3 dinner\n" );
scanf ("%d",&choice);
for (int num = 1; num <= 4; num++)
{

if ( choice == 1)
{
printf ("\v\t\t Breakfast Menu\n" );
printf ("\t\t -1 tea and bread only\n \t\t -2 tea, bread and egg\n \t\t -3 cup of coffee\n \t\t -4 fried chips with fish\n \t\t -5 fried chips with beef\n" );

scanf ("%d",&food);
if ( food == 1 || food == 2 || food == 3 || food == 4 || food == 5)
{
printf ("\t\t Thank you, your order has been recieved\n\t\t your breakfast will be served shortly\n" );
break;
}
if ( food >=6)
{
printf ( "\v\t\t invalid input try again\n" );
}
}
if ( choice == 2)
{
printf ("\v\t\t Lunch Menu\n" );
printf ("\t\t -1 rice and stew with beef \n \t\t -2 rice and stew with chicken\n \t\t -3 rice and stew with fish\n \t\t -4 garri and egusi soup\n \t\t -5 garri and okro soup\n" );
scanf ("%d",&food);
if ( food == 1 || food == 2 || food == 3 || food == 4 || food == 5)
{
printf ("\t\t Thank you, your order has been recieved\n\t\t your lunch will be served shortly\n" );
break;
}
if ( food >=6)
{
printf ( "\v\t\t invalid input try again\n" );
}
}
if ( choice == 3)
{
printf ("\v\t\t DINNER MENU\n" );
printf ("\t\t -1 fried yam and stew\n \t\t -2 fried yam and ketchup\n \t\t -3 fried potato chip with ketchup\n \t\t -4 spaggetti\n \t\t -5 macaroni\n" );
int food;
scanf ("%d",&food);
if ( food == 1 || food == 2 || food == 3 || food == 4 || food == 5)
{
printf ("\t\t Thank you, your order has been recieved\n\t\t your dinner will be served shortly\n" );
break;
}
if ( food >=6)
{
printf ( "\v\t\t invalid input try again\n" );
}
}


}
}

1 Like

Re: C++ Beginner Discussion Room: Drop Your Codes by adelolaa(m): 7:40pm On Dec 18, 2013
raynold: i just finished writing this program in c
\\ restaurant menu program


#include<stdio.h>
#include<stdlib.h>

main()
{
int food;
int choice;
printf ("\t\t WELCOME TO AKPOS RESTAURANT\n" );
printf ("\t\t Menu for today\n" );

printf ("\t\t Enter category\n \t\t -1 Breakfast\n \t\t -2 launch\n \t\t -3 dinner\n" );
scanf ("%d",&choice);
for (int num = 1; num <= 4; num++)
{

if ( choice == 1)
{
printf ("\v\t\t Breakfast Menu\n" );
printf ("\t\t -1 tea and bread only\n \t\t -2 tea, bread and egg\n \t\t -3 cup of coffee\n \t\t -4 fried chips with fish\n \t\t -5 fried chips with beef\n" );

scanf ("%d",&food);
if ( food == 1 || food == 2 || food == 3 || food == 4 || food == 5)
{
printf ("\t\t Thank you, your order has been recieved\n\t\t your breakfast will be served shortly\n" );
break;
}
if ( food >=6)
{
printf ( "\v\t\t invalid input try again\n" );
}
}
if ( choice == 2)
{
printf ("\v\t\t Luanch Menu\n" );
printf ("\t\t -1 rice and stew with beef \n \t\t -2 rice and stew with chicken\n \t\t -3 rice and stew with fish\n \t\t -4 garri and egusi soup\n \t\t -5 garri and okro soup\n" );
scanf ("%d",&food);
if ( food == 1 || food == 2 || food == 3 || food == 4 || food == 5)
{
printf ("\t\t Thank you, your order has been recieved\n\t\t your launch will be served shortly\n" );
break;
}
if ( food >=6)
{
printf ( "\v\t\t invalid input try again\n" );
}
}
if ( choice == 3)
{
printf ("\v\t\t DINNER MENU\n" );
printf ("\t\t -1 fried yam and stew\n \t\t -2 fried yam and ketchup\n \t\t -3 fried potato chip with ketchup\n \t\t -4 spaggetti\n \t\t -5 macaroni\n" );
int food;
scanf ("%d",&food);
if ( food == 1 || food == 2 || food == 3 || food == 4 || food == 5)
{
printf ("\t\t Thank you, your order has been recieved\n\t\t your breakfast will be served shortly\n" );
break;
}
if ( food >=6)
{
printf ( "\v\t\t invalid input try again\n" );
}
}


}
}


nice work. time to move on to chapter six
Re: C++ Beginner Discussion Room: Drop Your Codes by wisemania(m): 10:45am On Dec 19, 2013
//soln in C to the menu program
//make una no vex say he long o
//bear with me grin
//code inspired by raynold

#include <stdio.h>
void menu(void);
int main()
{
int order, i;
i = 0;

printf("Welcome to xarm's restaurant.\n" );
printf("Buy four bottles of drinks and get an extra drink for FREE!\n" );

a: printf("enter a digit from one through seven(1 - 7) to place an order(enter a to quit)\n" );

menu(); //callin the menu
//function

printf("your order please: " );

while(scanf("%d", &order)){
if( order > 0){
i++;
if (order == 1)
printf("here is your bottle of Coca-cola\n" );

if (order == 2)
printf("here is your bottle of Fanta\n" );

if (order == 3)
printf("here is your bottle of Pepsi\n" );

if (order == 4)
printf("here is your bottle of Koko-Malt\n" );

if (order == 5)
printf("here is your bottle of Malta-Guiness\n" );

if (order == 6)
printf("here is your bottle of Amstel-Malta\n" );

if (order >= 7){
c: printf("Invalid selection!\n" );
printf("\n" );
goto a;
}
}

else{
printf("Invalid selection" );
printf("\n" );
goto a;
}
printf("\n" );
printf("Your next order please(enter a to quit): " );
}
if (i > 0){

printf("Thanks alot for your patronage\n" );
printf("You ordered for %d botles, and that includes your free drink\n", i+1 );
printf("see the cashier on your way out to pick up your tab\n" );
goto b;
}
else{
printf("Please endeavour to patronize us when next you visit.We do love you!\n" );
goto d;
}
b: printf("We do hope you'd call back at our restaurant some other time.Bye for now we love you!\n" );

d: printf("Program terminated!\n" );
return 0;
}
void menu(void){

printf("1.Coca-cola(#70)\t2.Fanta(#70)\n3.Pepsi(#70)\t4.Koko-Malt(#100)\n5.Malta-Guiness(#120)\t6.Amstel-Malta(#120)\n7.Sprite(#70).\n" );
}

1 Like

Re: C++ Beginner Discussion Room: Drop Your Codes by raynold(m): 11:06am On Dec 19, 2013
wisemania: //soln in C to the menu program
//make una no vex say he long o
//bear with me grin
//code inspired by raynold

#include <stdio.h>
void menu(void);
int main()
{
int order, i;
i = 0;

printf("Welcome to xarm's restaurant.\n" );
printf("Buy four bottles of drinks and get an extra drink for FREE!\n" );

a: printf("enter a digit from one through seven(1 - 7) to place an order(enter a to quit)\n" );

menu(); //callin the menu
//function

printf("your order please: " );

while(scanf("%d", &order)){
if( order > 0){
i++;
if (order == 1)
printf("here is your bottle of Coca-cola\n" );

if (order == 2)
printf("here is your bottle of Fanta\n" );

if (order == 3)
printf("here is your bottle of Pepsi\n" );

if (order == 4)
printf("here is your bottle of Koko-Malt\n" );

if (order == 5)
printf("here is your bottle of Malta-Guiness\n" );

if (order == 6)
printf("here is your bottle of Amstel-Malta\n" );

if (order == 7){
c: printf("Invalid selection!\n" );
printf("\n" );
goto a;
}
}

else{
printf("Invalid selection" );
printf("\n" );
goto a;
}
printf("\n" );
printf("Your next order please(enter a to quit): " );
}
if (i > 0){

printf("Thanks alot for your patronage\n" );
printf("You ordered for %d botles, and that includes your free drink\n", i+1 );
printf("see the cashier on your way out to pick up your tab\n" );
goto b;
}
else{
printf("Please endeavour to patronize us when next you visit.We do love you!\n" );
goto d;
}
b: printf("We do hope you'd call back at our restaurant some other time.Bye for now we love you!\n" );

d: printf("Program terminated!\n" );
return 0;
}
void menu(void){

printf("1.Coca-cola(#70)\t2.Fanta(#70)\n3.Pepsi(#70)\t4.Koko-Malt(#100)\n5.Malta-Guiness(#120)\t6.Amstel-Malta(#120)\n7.Sprite(#70).\n" );
}
really nice program. love the way a customer is able to order more than one drinks unlike mine..
Re: C++ Beginner Discussion Room: Drop Your Codes by raynold(m): 11:18am On Dec 19, 2013
"while(scanf("%d", &order))"
this part kinda confused me a bit, had no idea it was possible
Re: C++ Beginner Discussion Room: Drop Your Codes by Leopantro: 11:37am On Dec 19, 2013
have got my eye on this thread for a while it says for beginners and i'm in the class below dumm.ies. was wondering if i could utilize any of the codes above in the android app "c4droid" to learn c++?
Re: C++ Beginner Discussion Room: Drop Your Codes by raynold(m): 11:57am On Dec 19, 2013
Leopantro: have got my eye on this thread for a while it says for beginners and i'm in the class below dumm.ies. was wondering if i could utilize any of the codes above in the android app "c4droid" to learn c++?
yes its kinda possible but note not all the codes here are c++.. it will be alot easier if u get the books tho like jumping into c++..
Re: C++ Beginner Discussion Room: Drop Your Codes by Leopantro: 12:13pm On Dec 19, 2013
thanks
Re: C++ Beginner Discussion Room: Drop Your Codes by wisemania(m): 2:12pm On Dec 19, 2013
raynold: really nice program. love the way a customer is able to order more than one drinks unlike mine..

thanks bro....u inspired it...
U alreedy kw dat "scanf("%d", order)" tells d compiler to prompt d user to enter one digit number...
Putting it in a while loop tells d compiler to kip on requesting for a digit number..so once a digit is entered, the reamaing nested "if" loop is being trigered.....
Bt if a non digit number is entered,...eg characters like (a-z,; . : - = @ etc) dat arnt numbers(dont fit into the scanf() digit format specifier"%d"wink den d inner if loops wont be executed....thus the program is terminated....
*dazall*
Re: C++ Beginner Discussion Room: Drop Your Codes by raynold(m): 2:32pm On Dec 19, 2013
wisemania:

thanks bro....u inspired it...
U alreedy kw dat "scanf("%d", order)" tells d compiler to prompt d user to enter one digit number...
Putting it in a while loop tells d compiler to kip on requesting for a digit number..so once a digit is entered, the reamaing nested "if" loop is being trigered.....
Bt if a non digit number is entered,...eg characters like (a-z,; . : - = @ etc) dat arnt numbers(dont fit into the scanf() digit format specifier"%d"wink den d inner if loops wont be executed....thus the program is terminated....
*dazall*
thanks.. am not really fun of while loop.. thanks for explaining it..

(1) (2) (3) (4) (5) (Reply)

Letter From The Moderator - Please Read / Steering The Wheel Of Tech Startups In Nigeria / Computer Science/programming Challenging Questions

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 117
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.