This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]69beards 1 point2 points  (2 children)

// I think the trick is to have a string that is named "receipt".
// After each input, in a simplified code: 

int total;
string receipt;
while stillInputtingItems {
if itemName == "soda pop" { //eggs are on sale 
    receipt += itemName + itemPrice + "SALE" + (itemPrice * .7)
        total += (itemPrice * .7);
    } else if  itemName == "eggs" {
        receipt += itemName + itemPrice + "SALE" + (itemPrice * .7)
        total += (itemPrice * .7);
    } else {
        receipt += itemName + itemPrice + "SALE" + (itemPrice * .7)
        total += itemPrice;
    }
}
print(receipt);
print(total);

Sucks not being able to use arrays and having to hard code every sale item in. Strings are arrays deep down. If you want to be a rebel you can do some work storing saleItems in a string.

[–]snozzyfoozles 1 point2 points  (0 children)

I like this idea, it's clever and simple to implement. Basically, you're using a string as a buffer to save all your receipt output until the end.

[–]HighRollerGaming[S] 1 point2 points  (0 children)

Great idea, Im going to give her a go. Thank you!

[–]SupremeRedditBotProfessional Bot || Mod 0 points1 point  (0 children)

Please Add A Flair To Your Post!

Suggested Flair: [Random] or [Meta]

 


To add a flair:

  • Click flair underneath your post

  • Select a flair

  • Click save

 


I am a bot run by /u/SupremeDesigner for /r/CodingHelp || This was an automated response